Compare commits
2 Commits
420b876a7a
...
fbce0c006c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbce0c006c | ||
|
|
fc1484aebe |
24
cmd/web/middleware.go
Normal file
24
cmd/web/middleware.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
func secureHeaders(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Security-Policy",
|
||||
"default-src 'self'; style-src 'self' fonts.googleapis.com; font-src fonts.gstatic.com")
|
||||
w.Header().Set("Referrer-Policy", "origin-when-cross-origin")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.Header().Set("X-Frame-Options", "deny")
|
||||
w.Header().Set("X-XSS-Protection", "0")
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func (app *application) logRequest(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
app.infoLog.Printf("%s - %s %s %s", r.RemoteAddr, r.Proto, r.Method, r.URL.RequestURI())
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
func (app *application) routes() *http.ServeMux {
|
||||
func (app *application) routes() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
fileServer := http.FileServer(http.Dir("./ui/static/"))
|
||||
@@ -12,5 +12,5 @@ func (app *application) routes() *http.ServeMux {
|
||||
mux.HandleFunc("/snippet/view", app.snippetView)
|
||||
mux.HandleFunc("/snippet/create", app.snippetCreate)
|
||||
|
||||
return mux
|
||||
return app.logRequest(secureHeaders(mux))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user