Skip to content

Commit

Permalink
Merge pull request #1 from theplant/statuscode-context
Browse files Browse the repository at this point in the history
Add statuscode in request context
  • Loading branch information
ericwo authored Jun 21, 2019
2 parents 3e110fb + 416b294 commit 6facad0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions notfound.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package custom404

import "net/http"
import (
"context"
"net/http"
)

type notfoundHandler struct {
mux http.Handler
Expand Down Expand Up @@ -33,7 +36,8 @@ func (nf *notfoundHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if nfw.notfound {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusNotFound)
nf.custom404.ServeHTTP(w, r)
newr := r.WithContext(context.WithValue(r.Context(), "statuscode", http.StatusNotFound))
nf.custom404.ServeHTTP(w, newr)
}
}

Expand Down

0 comments on commit 6facad0

Please # to comment.