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

Add RAW_URI to environ (as Gunicorn does) #1048

Closed
wants to merge 1 commit into from

Conversation

samuelfekete
Copy link

Add the original raw URI to environ, as Gunicorn does.

This provides access to the original request URI, without breaking existing code or standards. Simply using something like request.url wouldn't work if the client included URL-encoded characters like slash, equals, semi-colon or question-mark, as these would be unquoted and then not requoted.

Having the same environ name as in Gunicorn means we can use Gunicorn in production and Werkzeug server for development, and they will both have the same environ variable.

See also:
benoitc/gunicorn#1211 (comment)
#477

@tomviner
Copy link
Contributor

This seems like a no brainer to me. Otherwise there's simply no way to recover the client's original request URL.

@samuelfekete
Copy link
Author

@davidism, consider for example the original url:
http://localhost:8080/abc%2Fdef/ghi%3Bjkl;mnop
This ends up in environ as:
'PATH_INFO': '/abc/def/ghi;jkl;mnop'
and with request.url as:
http://localhost:8080/abc/def/ghi%3Bjkl%3Bmnop

Any distinction between URL-encoded slashes and actual slashes (or semicolons) are lost. However, these would still be recoverable from RAW_URI, which contains /abc%2Fdef/ghi%3Bjkl;mnop.

This issue has been raised before #797, but closed by @mitsuhiko as changing the behaviour would break backwards compatibility. The change I propose, adding RAW_URI, will not break backwards compatibility and enable the recovery of the original URL when needed.

@mitsuhiko
Copy link
Contributor

The entire idea of being able to get a "raw URL" is flawed. If we provide the key developers get the idea that they can depend on that being there. So I prefer not having that.

@mitsuhiko mitsuhiko closed this Jan 27, 2017
@samuelfekete
Copy link
Author

samuelfekete commented Jan 27, 2017

@mitsuhiko, the key is available in Gunicorn, which we use in production, and we have the requirement that the encoded characters must be allowed in the path, so it would be nice to have it in Werkzeug too, so that we can use it as a development server.

@mitsuhiko
Copy link
Contributor

and we have the requirement that the encoded characters must be allowed in the path

And this is precisely why I will not add this to Werkzeug. Once that key is there developers start to think this is something they can depend on but you can't. Raw URLs cannot be preserved in many environments. You can monkey patch it in now that you already depend on it but to prevent others from making this mistake in the future I do not want to have this in as a general feature.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants