Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make resumable uploads work from browser with signed url #1022

Merged
merged 3 commits into from Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions fakestorage/object.go
Expand Up @@ -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", "*")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the docs for GCS API, it seems that this should be configured in the bucket and honored by fake-gcs-server? https://cloud.google.com/storage/docs/configuring-cors#rest-apis

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointer (and all your excellent work with this project)!

On quick look it seems the necessary work is:

  1. add a handler for PATCH to /storage/v1/b/BUCKET_NAME?fields=cors that stores the configuration somewhere (do you have a pointer to existing code that shows the preferred way to store this type of config?)
  2. load that config at this step and set the header.

Seems pretty straightforward, but being new to go and not having too much time to dive deeply, I'd appreciate a pointer to code with the preferred config set/get approach.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, thinking a bit more about this, this one is tricky for the same versioning is tricky with the

The filesystem backend currently doesn't support storing any bucket attributes, so that would be a requirement. I don't want to make this PR too large for you.

I opened #1025, we can merge this PR as is to get you unblocked.

I've merged some other changes though, so please rebase your PR so we can get it ready to ship.


if ranged && !satisfiable {
status = http.StatusRequestedRangeNotSatisfiable
Expand Down
3 changes: 2 additions & 1 deletion fakestorage/server.go
Expand Up @@ -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(
Expand All @@ -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)
Expand Down