Skip to content

Commit

Permalink
Make resumable uploads work from browser with signed url (#1022)
Browse files Browse the repository at this point in the history
* Expose location header for cors requests

* Add missing Access-Control-Allow-Origin header for get request

* Add Content-Range to allowed headers
jasonford authored Dec 28, 2022
1 parent 041da75 commit e6f1413
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions fakestorage/object.go
Original file line number Diff line number Diff line change
@@ -813,6 +813,7 @@ func (s *Server) downloadObject(w http.ResponseWriter, r *http.Request) {
for name, value := range obj.Metadata {
w.Header().Set("X-Goog-Meta-"+name, value)
}
w.Header().Set("Access-Control-Allow-Origin", "*")

if ranged && !satisfiable {
status = http.StatusRequestedRangeNotSatisfiable
3 changes: 2 additions & 1 deletion fakestorage/server.go
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ func NewServerWithOptions(options Options) (*Server, error) {
return nil, err
}

allowedHeaders := []string{"Content-Type", "Content-Encoding", "Range"}
allowedHeaders := []string{"Content-Type", "Content-Encoding", "Range", "Content-Range"}
allowedHeaders = append(allowedHeaders, options.AllowedCORSHeaders...)

cors := handlers.CORS(
@@ -140,6 +140,7 @@ func NewServerWithOptions(options Options) (*Server, error) {
handlers.AllowedHeaders(allowedHeaders),
handlers.AllowedOrigins([]string{"*"}),
handlers.AllowCredentials(),
handlers.ExposedHeaders([]string{"Location"}),
)

handler := cors(s.mux)

0 comments on commit e6f1413

Please sign in to comment.