Skip to content

Define REQUEST_URI environ variable. #5

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions proposal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,15 @@ unless their value would be an empty string, in which case they
server's response. However, for compatibility with CGI we have to
keep the existing name.)

``REQUEST_URI``
The complete, un-normalized, raw request URI as provided by the user-agent.
This must be everything in the URI from the beginning of the path component
onwards. It must begin with a leading slash, and **may** contain only that
slash (if the root was requested). This field is new in WSGI 1.1, and so
applications must check for the WSGI version tuple before relying on this
field. This field **must** be a native string, as defined in
`A Note On String Types`_.

``HTTP_`` Variables
Variables corresponding to the client-supplied HTTP request headers
(i.e., variables whose names begin with ``"HTTP_"``). The presence or
Expand Down Expand Up @@ -1365,11 +1374,33 @@ to re-read it upon each invocation.)
URL Reconstruction
------------------

If an application wishes to reconstruct a request's complete URL, it
may do so using the following algorithm, contributed by Ian Bicking::
If an application wishes to reconstruct a request's complete URL when
interoperating with a server using WSGI 1.1, it may do so using the following
simple algorithm::

url = environ['wsgi.url_scheme'] + '://'

if environ.get('HTTP_HOST'):
url += environ['HTTP_HOST']
else:
url += environ['SERVER_NAME']

if environ['wsgi.url_scheme'] == 'https':
if environ['SERVER_PORT'] != '443':
url += ':' + environ['SERVER_PORT']
else:
if environ['SERVER_PORT'] != '80':
url += ':' + environ['SERVER_PORT']

url += quote(environ.get('REQUEST_URI', '/'))

If an application wishes to reconstruct a request's complete URL when
interoperating with a server using an earlier version of WSGI, the application
may do so with the somewhat more complex algorithm below, contributed by Ian
Bicking::

from urllib import quote
url = environ['wsgi.url_scheme']+'://'
url = environ['wsgi.url_scheme'] + '://'

if environ.get('HTTP_HOST'):
url += environ['HTTP_HOST']
Expand All @@ -1393,6 +1424,12 @@ as requested by the client. Server rewrite rules, for example, may
have modified the client's originally requested URL to place it in a
canonical form.

Additionally, the variant used for versions of WSGI older than WSGI 1.1 may
lead to a URL that is different to the one provided by the client, even if no
server rewrite rules were in place. For example, the client may have quoted
spaces differently than ``urllib.quote`` does. The WSGI 1.1 version using
``REQUEST_URI`` avoids this problem.


Supporting Older (<2.2) Versions of Python
------------------------------------------
Expand Down