fup/fuphttp: add badRequest handler

We might get bad requests for e.g. file uploads, so we should have an error
handler for that.

This also disables mime type sniffing for the other text/plain error handler.
This commit is contained in:
Luke Granger-Brown 2021-03-21 17:08:29 +00:00
parent 5d9b444a56
commit 7eac2c0c07

View file

@ -83,11 +83,19 @@ func (a *Application) notFound(rw http.ResponseWriter, r *http.Request) {
}
func (a *Application) internalError(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("Content-type", "text/plain")
rw.Header().Set("Content-type", "text/plain; charset=utf-8")
rw.Header().Set("X-Content-Type-Options", "nosniff")
rw.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(rw, "hammed server :(\n")
}
func (a *Application) badRequest(rw http.ResponseWriter, r *http.Request, err error) {
rw.Header().Set("Content-type", "text/plain; charset=utf-8")
rw.Header().Set("X-Content-Type-Options", "nosniff")
rw.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(rw, "bad request: %v\n", err.Error())
}
func parseTemplate(t *template.Template, fsys fs.FS, name string) (*template.Template, error) {
bs, err := fs.ReadFile(fsys, name)
if err != nil {