mirror of
https://github.com/offen/website.git
synced 2024-11-22 17:10:29 +01:00
30 lines
871 B
Go
30 lines
871 B
Go
package http
|
|
|
|
import "net/http"
|
|
|
|
func CorsMiddleware(next http.Handler, origin string) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Access-Control-Allow-Credentials", "true")
|
|
w.Header().Set("Access-Control-Allow-Methods", "POST,GET")
|
|
w.Header().Set("Access-Control-Allow-Origin", origin)
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
|
|
func ContentTypeMiddleware(next http.Handler, contentType string) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Add("Content-Type", contentType)
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
|
|
func DoNotTrackMiddleware(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if dnt := r.Header.Get("DNT"); dnt == "1" {
|
|
w.WriteHeader(http.StatusNoContent)
|
|
return
|
|
}
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|