|
@@ -20,21 +20,21 @@ type middleware struct {
|
|
|
func newMiddleware(s *storage.Storage) *middleware {
|
|
func newMiddleware(s *storage.Storage) *middleware {
|
|
|
return &middleware{s}
|
|
return &middleware{s}
|
|
|
}
|
|
}
|
|
|
-func (m *middleware) handleCORS(next http.Handler) http.Handler {
|
|
|
|
|
|
|
+func (m *middleware) withCORSHeaders(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("Access-Control-Allow-Origin", "*")
|
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
|
|
w.Header().Set("Access-Control-Allow-Headers", "X-Auth-Token, Authorization, Content-Type, Accept")
|
|
w.Header().Set("Access-Control-Allow-Headers", "X-Auth-Token, Authorization, Content-Type, Accept")
|
|
|
if r.Method == http.MethodOptions {
|
|
if r.Method == http.MethodOptions {
|
|
|
w.Header().Set("Access-Control-Max-Age", "3600")
|
|
w.Header().Set("Access-Control-Max-Age", "3600")
|
|
|
- w.WriteHeader(http.StatusOK)
|
|
|
|
|
|
|
+ response.NoContent(w, r)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
next.ServeHTTP(w, r)
|
|
next.ServeHTTP(w, r)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (m *middleware) apiKeyAuth(next http.Handler) http.Handler {
|
|
|
|
|
|
|
+func (m *middleware) validateAPIKeyAuth(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) {
|
|
|
clientIP := request.ClientIP(r)
|
|
clientIP := request.ClientIP(r)
|
|
|
token := r.Header.Get("X-Auth-Token")
|
|
token := r.Header.Get("X-Auth-Token")
|
|
@@ -87,7 +87,7 @@ func (m *middleware) apiKeyAuth(next http.Handler) http.Handler {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (m *middleware) basicAuth(next http.Handler) http.Handler {
|
|
|
|
|
|
|
+func (m *middleware) validateBasicAuth(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) {
|
|
|
if request.IsAuthenticated(r) {
|
|
if request.IsAuthenticated(r) {
|
|
|
next.ServeHTTP(w, r)
|
|
next.ServeHTTP(w, r)
|