mercurial/hgweb/request.py
branchstable
changeset 37818 877185de62cf
parent 37616 5e81cf9651c1
child 37825 e82b137a8b4e
equal deleted inserted replaced
37817:678ab0de7296 37818:877185de62cf
   122     # Request body input stream.
   122     # Request body input stream.
   123     bodyfh = attr.ib()
   123     bodyfh = attr.ib()
   124     # WSGI environment dict, unmodified.
   124     # WSGI environment dict, unmodified.
   125     rawenv = attr.ib()
   125     rawenv = attr.ib()
   126 
   126 
   127 def parserequestfromenv(env, reponame=None, altbaseurl=None):
   127 def parserequestfromenv(env, reponame=None, altbaseurl=None, bodyfh=None):
   128     """Parse URL components from environment variables.
   128     """Parse URL components from environment variables.
   129 
   129 
   130     WSGI defines request attributes via environment variables. This function
   130     WSGI defines request attributes via environment variables. This function
   131     parses the environment variables into a data structure.
   131     parses the environment variables into a data structure.
   132 
   132 
   142     is made to ``/rev/@`` with this argument set to
   142     is made to ``/rev/@`` with this argument set to
   143     ``http://myserver:9000/prefix``, the URL and path components will resolve as
   143     ``http://myserver:9000/prefix``, the URL and path components will resolve as
   144     if the request were to ``http://myserver:9000/prefix/rev/@``. In other
   144     if the request were to ``http://myserver:9000/prefix/rev/@``. In other
   145     words, ``wsgi.url_scheme``, ``SERVER_NAME``, ``SERVER_PORT``, and
   145     words, ``wsgi.url_scheme``, ``SERVER_NAME``, ``SERVER_PORT``, and
   146     ``SCRIPT_NAME`` are all effectively replaced by components from this URL.
   146     ``SCRIPT_NAME`` are all effectively replaced by components from this URL.
       
   147 
       
   148     ``bodyfh`` can be used to specify a file object to read the request body
       
   149     from. If not defined, ``wsgi.input`` from the environment dict is used.
   147     """
   150     """
   148     # PEP 3333 defines the WSGI spec and is a useful reference for this code.
   151     # PEP 3333 defines the WSGI spec and is a useful reference for this code.
   149 
   152 
   150     # We first validate that the incoming object conforms with the WSGI spec.
   153     # We first validate that the incoming object conforms with the WSGI spec.
   151     # We only want to be dealing with spec-conforming WSGI implementations.
   154     # We only want to be dealing with spec-conforming WSGI implementations.
   305         headers['Content-Length'] = env['CONTENT_LENGTH']
   308         headers['Content-Length'] = env['CONTENT_LENGTH']
   306 
   309 
   307     if 'CONTENT_TYPE' in env and 'HTTP_CONTENT_TYPE' not in env:
   310     if 'CONTENT_TYPE' in env and 'HTTP_CONTENT_TYPE' not in env:
   308         headers['Content-Type'] = env['CONTENT_TYPE']
   311         headers['Content-Type'] = env['CONTENT_TYPE']
   309 
   312 
   310     bodyfh = env['wsgi.input']
   313     if bodyfh is None:
   311     if 'Content-Length' in headers:
   314         bodyfh = env['wsgi.input']
   312         bodyfh = util.cappedreader(bodyfh, int(headers['Content-Length']))
   315         if 'Content-Length' in headers:
       
   316             bodyfh = util.cappedreader(bodyfh, int(headers['Content-Length']))
   313 
   317 
   314     return parsedrequest(method=env['REQUEST_METHOD'],
   318     return parsedrequest(method=env['REQUEST_METHOD'],
   315                          url=fullurl, baseurl=baseurl,
   319                          url=fullurl, baseurl=baseurl,
   316                          advertisedurl=advertisedfullurl,
   320                          advertisedurl=advertisedfullurl,
   317                          advertisedbaseurl=advertisedbaseurl,
   321                          advertisedbaseurl=advertisedbaseurl,