2019-06-06 13:06:31 +02:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-24 22:26:50 +02:00
|
|
|
func OptoutMiddleware(next http.Handler) http.Handler {
|
2019-06-06 13:06:31 +02:00
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2019-06-24 22:26:50 +02:00
|
|
|
if _, err := r.Cookie("optout"); err == nil {
|
2019-06-06 13:06:31 +02:00
|
|
|
w.WriteHeader(http.StatusNoContent)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
})
|
|
|
|
}
|