-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Added in basic CORS support. #183
Conversation
…sation of allowed headers though.
Really nice!! Thanks |
I'm not sure it's a good idea to auto respond to OPTIONS request, shouldn't it be the responsibility of the application server to handle that ? you can reproduce my test with this gist: https://gist.github.com/mathroc/5b2bb374854878511d9a |
I agree that it should be the responsibility of the application server to handle the request. However, my analysis using tcpdump shows that OPTIONS requests are converted to GET requests when proxied (which is a Bad Thing) and I couldn't find a way around it. My pull request is only suitable for a dev environment where there is no requirement to control the result of the OPTIONS preflight. As for the proxy_pass headers, I agree but it makes the intention of the configuration explicit. As I also note, the pull request makes no allowances for additional allowed headers. Really, the pull request is a starting point and certainly needs more work but it's better than we had before :) |
well, I've upgraded the gist to show print the http method, and use this curl call to test it : in my case it's not converted to a GET request:
can you explain how to reproduce your observations ? |
My observations come from switching a dev setup that works correctly without the proxy in the middle and then debugging the problem which, as I say, was due to OPTIONS requests being passed through as GET requests. My setup is an apache 2.4 server in a container linked to a php5.5 fpm container on tcp port 9000. The apache container is being proxied by the nginx-proxy container. The client requests are coming from jQuery. Because the requests are for json data the accept header is for json. I debugged the issue by tcpdump'ing the data flow in and out of the proxy container and it is easy enough to see the incoming preflight OPTIONS request being converted into a GET request as it is passed on to apache and then seeing the real GET request coming in afterwards. Because I'm seeing the traffic in and out of the proxy I've discounted any issue between apache and fpm. Because I know it works correctly (apache / php respond to the OPTIONS preflight correctly) when the proxy isn't in the middle my deduction is that the proxy is the piece changing the OPTIONS to a GET. As your tests don't show this behaviour I'd guess it has something to do with which headers are passed - e.g. changing the Accept header. |
This is better to be handed by a custom template by the user than having it in the default image. |
Unlike when this PR was created, I think it's now possible to achieve an equivalent setup by extending this image with the |
I've added a list of headers the proxy should allow to pass through so a server can respond to CORS requests. I've also made the proxy auto-respond to OPTIONS requests with a basic, pretty permissive CORS reply.
This won't support situations where the proxied server wishes to customise the OPTIONS reply.
Could do with something to allow customisation of allowed headers though.