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
Properly set PATH_INFO when X-outside-url header with path is used #942
Conversation
When the `X-outside-url` header is passed in a request to devpi-server, the path portion is set as the wsgi `SCRIPT_NAME` variable so it can run in a subpath. However, the wsgi spec [1] states that `SCRIPT_NAME` and `PATH_INFO` together constitute the complete URL but `PATH_INFO` isn't modified. This commit adds stripping of the `SCRIPT_NAME` from the beginning of `PATH_INFO`. [1] https://wsgi.readthedocs.io/en/latest/definitions.html#standard-environ-keys
Does this solve an actual bug? Are there any wrongly generated URLs? If so, please try to add a test that shows that. If you need help with that, please let me know. |
Sorry if it wasn't clear if or what bug it solves, I was a bit in a rush yesterday. My goal was to serve devpi-server via a reverse proxy in a sub path like I just had a look at the tests and managed to run the test suite successfully in its current state, but I'm a bit lost in all the layers of the testing harness around the app object. In order to debug and reproduce the redirection loop I tried to For reference, here are the relevant code section of waitress and webtest for treating |
I guess that it fixes #934 then. Now that I know what this is about, I can do the rest, as a test for it is certainly not trivial without knowing the suite quite well. |
Yes, it should solve #934 👍 There is one important question that was really hard for me to answer when trying to understand how to use a setup with Reagrding path stripping, this PR actually (unintentionally) allows both behaviours because it only strips the prefix from incoming requests conditionally, i.e. if it matches. I think it's the same behaviour like in waitress. |
I tried writing a test case, but couldn't create anything that fails without this fix. It would be super useful to get the request headers devpi-server receives for the redirect loop case, or maybe you can point to the code that generates the wrong redirect when |
To be clear, I agree that your change looks correct according to the specs and your waitress, webtest links, but a failing test would be really nice. |
Found my mistake. I have a test which shows this fix works as intended. |
Merged by hand. |
When the
X-outside-url
header is passed in a request to devpi-server, the path portion is set as the wsgiSCRIPT_NAME
variable so it can run in a subpath. However, the wsgi spec [1] states thatSCRIPT_NAME
andPATH_INFO
together constitute the complete URL butPATH_INFO
isn't modified. This commit adds stripping of theSCRIPT_NAME
from the beginning ofPATH_INFO
.[1] https://wsgi.readthedocs.io/en/latest/definitions.html#standard-environ-keys
For reference, here are two minimal configs for traefik and nginx to to serve devpi on the sub path
/devpi
nginx.conf
traefik labels (for running in docker-compose)