summaryrefslogtreecommitdiff
path: root/srv/src/http/posts.go
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2022-05-20 19:19:32 -0600
committerBrian Picciano <mediocregopher@gmail.com>2022-05-20 19:19:32 -0600
commit1181af0318059e41d5564e6ef786122c7ee4c8e1 (patch)
tree9e9f18a21892af880672f944471d9033bfbf61e5 /srv/src/http/posts.go
parentc4692f72e3b0bf18f737add2bbd4e353274fe3ac (diff)
Don't use EDIT method, only POSTs should use alt methods
Diffstat (limited to 'srv/src/http/posts.go')
-rw-r--r--srv/src/http/posts.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/srv/src/http/posts.go b/srv/src/http/posts.go
index e1ddf80..c779eed 100644
--- a/srv/src/http/posts.go
+++ b/srv/src/http/posts.go
@@ -84,14 +84,20 @@ func (a *api) postToPostTplPayload(storedPost post.StoredPost) (postTplPayload,
func (a *api) renderPostHandler() http.Handler {
tpl := a.mustParseBasedTpl("post.html")
- renderIndexHandler := a.renderPostsIndexHandler()
+ renderPostsIndexHandler := a.renderPostsIndexHandler()
+ renderEditPostHandler := a.renderEditPostHandler()
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
id := strings.TrimSuffix(filepath.Base(r.URL.Path), ".html")
if id == "/" {
- renderIndexHandler.ServeHTTP(rw, r)
+ renderPostsIndexHandler.ServeHTTP(rw, r)
+ return
+ }
+
+ if _, ok := r.URL.Query()["edit"]; ok {
+ renderEditPostHandler.ServeHTTP(rw, r)
return
}
@@ -167,7 +173,7 @@ func (a *api) renderPostsIndexHandler() http.Handler {
})
}
-func (a *api) editPostHandler() http.Handler {
+func (a *api) renderEditPostHandler() http.Handler {
tpl := a.mustParseBasedTpl("edit-post.html")
@@ -208,8 +214,9 @@ func postFromPostReq(r *http.Request) (post.Post, error) {
}
// textareas encode newlines as CRLF for historical reasons
+ p.Body = r.PostFormValue("body")
p.Body = strings.ReplaceAll(p.Body, "\r\n", "\n")
- p.Body = strings.TrimSpace(r.PostFormValue("body"))
+ p.Body = strings.TrimSpace(p.Body)
if p.ID == "" ||
p.Title == "" ||
@@ -239,7 +246,7 @@ func (a *api) postPostHandler() http.Handler {
return
}
- redirectPath := fmt.Sprintf("posts/%s?method=edit", p.ID)
+ redirectPath := fmt.Sprintf("posts/%s?edit", p.ID)
a.executeRedirectTpl(rw, r, redirectPath)
})