Create Cors handler with permissive configuration (#7186)

Create new Cors handler allowing all origins with all standard
methods with any header and credentials.

Fixes #7181
This commit is contained in:
kannappanr
2019-02-05 14:06:52 -08:00
committed by GitHub
parent 9a65f6dc97
commit df418a2783
6 changed files with 101 additions and 98 deletions

View File

@@ -381,37 +381,9 @@ type resourceHandler struct {
handler http.Handler
}
// List of default allowable HTTP methods.
var defaultAllowableHTTPMethods = []string{
http.MethodGet,
http.MethodPut,
http.MethodHead,
http.MethodPost,
http.MethodDelete,
http.MethodOptions,
}
// setCorsHandler handler for CORS (Cross Origin Resource Sharing)
func setCorsHandler(h http.Handler) http.Handler {
commonS3Headers := []string{
"Date",
"ETag",
"Server",
"Connection",
"Accept-Ranges",
"Content-Range",
"Content-Encoding",
"Content-Length",
"Content-Type",
"x-amz-request-id",
}
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: defaultAllowableHTTPMethods,
AllowedHeaders: []string{"*"},
ExposedHeaders: commonS3Headers,
AllowCredentials: true,
})
c := cors.AllowAll()
return c.Handler(h)
}