diff --git a/handlers.go b/handlers.go index a4bc55e..c9a6d8f 100644 --- a/handlers.go +++ b/handlers.go @@ -58,7 +58,7 @@ func (rl *rushlink) staticGetHandler(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) { @@ -189,7 +189,13 @@ func (rl *rushlink) viewPasteHandlerInnerMeta(w http.ResponseWriter, r *http.Req "CanDeleteString": cd.String(), "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 } @@ -212,7 +218,7 @@ func (rl *rushlink) viewActionSuccess(w http.ResponseWriter, r *http.Request, p "CanDeleteString": cd.String(), "CanDeleteBool": cd.Bool(), } - rl.render(w, r, "pasteMeta", data) + rl.render(w, r, 0, "pasteMeta", data) return } diff --git a/views.go b/views.go index 4e21c41..ba82c98 100644 --- a/views.go +++ b/views.go @@ -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)) } -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"}) if err != nil { w.WriteHeader(http.StatusNotAcceptable) @@ -139,7 +139,9 @@ func (rl *rushlink) render(w http.ResponseWriter, r *http.Request, tmplName stri } return buf.String() } - w.WriteHeader(http.StatusOK) + if status != 0 { + w.WriteHeader(status) + } if r.Method != "HEAD" { 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) { - w.WriteHeader(status) - rl.render(w, r, "error", map[string]interface{}{"Message": msg}) + rl.render(w, r, status, "error", map[string]interface{}{"Message": msg}) } func (rl *rushlink) renderInternalServerError(w http.ResponseWriter, r *http.Request, err interface{}) {