meta: Do 410 Gone if paste deleted

This commit is contained in:
Daan Sprenkels 2020-05-11 22:45:56 +02:00
parent b9119a0df5
commit 016ffa8949
2 changed files with 14 additions and 7 deletions

View File

@ -58,7 +58,7 @@ func (rl *rushlink) staticGetHandler(w http.ResponseWriter, r *http.Request) {
} }
func (rl *rushlink) indexGetHandler(w http.ResponseWriter, r *http.Request) { func (rl *rushlink) indexGetHandler(w http.ResponseWriter, r *http.Request) {
rl.render(w, r, "index", map[string]interface{}{}) rl.render(w, r, http.StatusOK, "index", map[string]interface{}{})
} }
func (rl *rushlink) viewPasteHandler(w http.ResponseWriter, r *http.Request) { func (rl *rushlink) viewPasteHandler(w http.ResponseWriter, r *http.Request) {
@ -189,7 +189,13 @@ func (rl *rushlink) viewPasteHandlerInnerMeta(w http.ResponseWriter, r *http.Req
"CanDeleteString": cd.String(), "CanDeleteString": cd.String(),
"CanDeleteBool": cd.Bool(), "CanDeleteBool": cd.Bool(),
} }
rl.render(w, r, "pasteMeta", data) var status int
if p.State == db.PasteStateDeleted {
status = http.StatusGone
} else {
status = http.StatusOK
}
rl.render(w, r, status, "pasteMeta", data)
return return
} }
@ -212,7 +218,7 @@ func (rl *rushlink) viewActionSuccess(w http.ResponseWriter, r *http.Request, p
"CanDeleteString": cd.String(), "CanDeleteString": cd.String(),
"CanDeleteBool": cd.Bool(), "CanDeleteBool": cd.Bool(),
} }
rl.render(w, r, "pasteMeta", data) rl.render(w, r, 0, "pasteMeta", data)
return return
} }

View File

@ -99,7 +99,7 @@ func (rl *rushlink) renderStatic(w http.ResponseWriter, r *http.Request, path st
http.ServeContent(w, r, path, modTime, bytes.NewReader(contents)) http.ServeContent(w, r, path, modTime, bytes.NewReader(contents))
} }
func (rl *rushlink) render(w http.ResponseWriter, r *http.Request, tmplName string, data map[string]interface{}) { func (rl *rushlink) render(w http.ResponseWriter, r *http.Request, status int, tmplName string, data map[string]interface{}) {
contentType, err := resolveResponseContentType(r, []string{"text/plain", "text/html"}) contentType, err := resolveResponseContentType(r, []string{"text/plain", "text/html"})
if err != nil { if err != nil {
w.WriteHeader(http.StatusNotAcceptable) w.WriteHeader(http.StatusNotAcceptable)
@ -139,7 +139,9 @@ func (rl *rushlink) render(w http.ResponseWriter, r *http.Request, tmplName stri
} }
return buf.String() return buf.String()
} }
w.WriteHeader(http.StatusOK) if status != 0 {
w.WriteHeader(status)
}
if r.Method != "HEAD" { if r.Method != "HEAD" {
err = tmpl.Execute(w, data) err = tmpl.Execute(w, data)
@ -156,8 +158,7 @@ func (rl *rushlink) render(w http.ResponseWriter, r *http.Request, tmplName stri
} }
func (rl *rushlink) renderError(w http.ResponseWriter, r *http.Request, status int, msg string) { func (rl *rushlink) renderError(w http.ResponseWriter, r *http.Request, status int, msg string) {
w.WriteHeader(status) rl.render(w, r, status, "error", map[string]interface{}{"Message": msg})
rl.render(w, r, "error", map[string]interface{}{"Message": msg})
} }
func (rl *rushlink) renderInternalServerError(w http.ResponseWriter, r *http.Request, err interface{}) { func (rl *rushlink) renderInternalServerError(w http.ResponseWriter, r *http.Request, err interface{}) {