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:
parent
5d9b444a56
commit
7eac2c0c07
1 changed files with 9 additions and 1 deletions
|
@ -83,11 +83,19 @@ func (a *Application) notFound(rw http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Application) internalError(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)
|
rw.WriteHeader(http.StatusInternalServerError)
|
||||||
fmt.Fprintf(rw, "hammed server :(\n")
|
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) {
|
func parseTemplate(t *template.Template, fsys fs.FS, name string) (*template.Template, error) {
|
||||||
bs, err := fs.ReadFile(fsys, name)
|
bs, err := fs.ReadFile(fsys, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue