From 81b255511fa2f15d05c75c9623ac0d82136a2775 Mon Sep 17 00:00:00 2001 From: Krishna Srinivas Date: Thu, 28 Jan 2016 22:53:05 +0530 Subject: [PATCH] CORS: cors handling should be before auth handling. cors should allow PUT. --- generic-handlers.go | 2 +- routers.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generic-handlers.go b/generic-handlers.go index fbd5981f3..cda47469c 100644 --- a/generic-handlers.go +++ b/generic-handlers.go @@ -126,7 +126,7 @@ func (h timeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func CorsHandler(h http.Handler) http.Handler { c := cors.New(cors.Options{ AllowedOrigins: []string{"*"}, - AllowedMethods: []string{"GET", "HEAD", "POST"}, + AllowedMethods: []string{"GET", "HEAD", "POST", "PUT"}, AllowedHeaders: []string{"*"}, }) return c.Handler(h) diff --git a/routers.go b/routers.go index 80d03755a..82d5be3a2 100644 --- a/routers.go +++ b/routers.go @@ -58,8 +58,8 @@ type WebAPI struct { func getWebAPIHandler(web *WebAPI) http.Handler { var mwHandlers = []MiddlewareHandler{ TimeValidityHandler, // Validate time. - CorsHandler, // CORS added only for testing purposes. AuthHandler, // Authentication handler for verifying tokens. + CorsHandler, // CORS added only for testing purposes. } if web.AccessLog { mwHandlers = append(mwHandlers, AccessLogHandler) @@ -157,7 +157,6 @@ func getNewCloudStorageAPI(conf cloudServerConfig) CloudStorageAPI { func getCloudStorageAPIHandler(api CloudStorageAPI) http.Handler { var mwHandlers = []MiddlewareHandler{ - CorsHandler, TimeValidityHandler, IgnoreResourcesHandler, IgnoreSignatureV2RequestHandler, @@ -168,6 +167,7 @@ func getCloudStorageAPIHandler(api CloudStorageAPI) http.Handler { if api.AccessLog { mwHandlers = append(mwHandlers, AccessLogHandler) } + mwHandlers = append(mwHandlers, CorsHandler) mux := router.NewRouter() registerCloudStorageAPI(mux, api) return registerCustomMiddleware(mux, mwHandlers...)