mirror of
https://github.com/fsouza/fake-gcs-server.git
synced 2026-04-25 21:55:56 +03:00
[PR #319] [MERGED] Add CORS Support #514
Labels
No labels
bug
compatibility-issue
docker
documentation
enhancement
help wanted
needs information
pull-request
question
stale
unfortunate
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/fake-gcs-server#514
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/fsouza/fake-gcs-server/pull/319
Author: @kenniaa
Created: 8/30/2020
Status: ✅ Merged
Merged: 9/12/2020
Merged by: @fsouza
Base:
main← Head:add-cors📝 Commits (5)
8cfcdf1Add CORS support8502c4eCustomize allowed headersccae498Update tests87783daSimplify if blockb6b0b30Default allowCORSHeaders to nil📊 Changes
4 files changed (+146 additions, -33 deletions)
View changed files
📝
fakestorage/server.go(+25 -2)📝
fakestorage/server_test.go(+75 -0)📝
internal/config/config.go(+27 -15)📝
internal/config/config_test.go(+19 -16)📄 Description
A big reason for supporting signed urls is the ability to initiate requests from the browser that insert files into the bucket instead of proxying files through your server.
Currently, this does not work in
fake-gcs-serverdue to CORS limitations, asfake-gcs-serverdoes not respond to any CORS preflight requests. From the browser, you may disable CORS checking (viano-corsonfetchor equivalent), but this severely limits what kind of requests you can make; with CORS checking disabled, you are unable to initiate a PUT request thereby preventing the above usecase.So to address this, I've added a simple CORS handler. It is intended to be maximally accepting, such that most requests will be accepted without configuration. Since this project is meant for testing GCS and not running in production, I did not see much of a reason for locking it down and instead opted for ease of use.
The one exception to this is
Access-Control-Allowed-Headers, because unfortunately Mux will not support wildcards for headers. This means that I instead had to audit what headersfake-gcs-serveraccepts and manually specify them in the allowlist-- I believe I have covered them all but I could be missing something (CORS requests never worked here, so I don't consider that a dealbreaker). Additionally, I've added a new command line flag for the end user to specify any additional headers they need to be present in the allowlist. I found this useful for the custom meta headers that you may attach to signed urls.I've added tests which should cover the necessary changes to config and server function, but please let me know if I should add any others!
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.