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

Support for CORS headers #74

Closed
vroudge opened this issue May 24, 2018 · 8 comments
Closed

Support for CORS headers #74

vroudge opened this issue May 24, 2018 · 8 comments
Assignees
Labels

Comments

@vroudge
Copy link

vroudge commented May 24, 2018

Hello!

I'm trying to use this to test a browser-based uploader. I get issues related to CORS. Is there anyway to set the cross origin headers with S3Mock ?

@agudian
Copy link
Member

agudian commented May 24, 2018

We don’t have that, yet. But I bet it can be added through Spring Boot...

@vroudge
Copy link
Author

vroudge commented May 24, 2018

That would be brilliant. I'm not a Java person myself, but I'll keep looking at this ticket, it's a very interesting feature.

@timoe
Copy link
Contributor

timoe commented Jun 6, 2018

@vroudge: Spring (Boot) offers CORS configuration (see: https://spring.io/blog/2015/06/08/cors-support-in-spring-framework). The most simple way to enable each and every origin would be to add a global mapping for each and every API S3Mock provides.

My current idea is to enabled origins and/or API endpoints via configuration. Before doing that, can give please give the usecase you're working on? Do you have any examples, code-snippets that let me verify this for your usecase?

Thanks
Timo

@timoe timoe self-assigned this Jun 6, 2018
mpiggott added a commit to mpiggott/S3Mock that referenced this issue Aug 28, 2021
@afranken
Copy link
Member

version 2.2.2 adds CORS headers for all origins (wildcard pattern).
Hope that helps.

lennartblom pushed a commit to lennartblom/S3Mock that referenced this issue Nov 24, 2021
@mikemonteith
Copy link

mikemonteith commented Dec 7, 2021

This change results in two identical Access-Control-Allow-Origin: * headers being set on the GET controller, which gives a browser error "Cross-Origin Request Blocked: .... (Reason: Multiple CORS header ‘Access-Control-Allow-Origin’ not allowed)."

There was already a cross origin http header being set here

.header(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, ANY)

I think the @CrossOrigin annotation is the correct way to do it, I will open a PR to remove the extra ACCESS_CONTROL_ALLOW_ORIGIN header unless someone else beats me to it.

@afranken
Copy link
Member

afranken commented Dec 7, 2021

@mikemonteith thx for alerting me - I'll remove the explicit setting you mentioned, just opened a PR :)

@mikemonteith
Copy link

Wow @afranken that was fast!

@afranken
Copy link
Member

afranken commented Dec 7, 2021

@mikemonteith thanks for providing the solution with the report :)

I was just merging the latest dependabot updates and then release, so it was easy to add in this trivial fix.
We unfortunately do not have any browser-related tests, and I was too lazy to manually test if the CORS headers are actually working. Maybe I'll add asserts to one of the integration tests when I find the time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants