lets-go:6.3 more middleware
This commit is contained in:
parent
8678a04350
commit
bee34e7405
@ -4,6 +4,21 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// logRequest ...
|
||||||
|
func (app *application) logRequest(next http.Handler) http.Handler {
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var (
|
||||||
|
ip = r.RemoteAddr
|
||||||
|
proto = r.Proto
|
||||||
|
method = r.Method
|
||||||
|
uri = r.URL.RequestURI()
|
||||||
|
)
|
||||||
|
|
||||||
|
app.logger.Info("received request", "ip", ip, "proto", proto, "method", method, "uri", uri)
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func secureHeaders(next http.Handler) http.Handler {
|
func secureHeaders(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Security-Policy",
|
w.Header().Set("Content-Security-Policy",
|
||||||
|
@ -16,5 +16,5 @@ func (app *application) routes() http.Handler {
|
|||||||
mux.HandleFunc("/snippet/view", app.snippetView)
|
mux.HandleFunc("/snippet/view", app.snippetView)
|
||||||
mux.HandleFunc("/snippet/create", app.snippetCreate)
|
mux.HandleFunc("/snippet/create", app.snippetCreate)
|
||||||
|
|
||||||
return secureHeaders(mux)
|
return app.logRequest(secureHeaders(mux))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user