changeset 36856:1f7d9024674c

hgweb: make parsedrequest part of wsgirequest This is kind of ugly. But an upcoming commit will teach parsedrequest about the input stream. Because the input stream is global state and can't be accessed without side-effects, we need to take actions to ensure that multiple consumers don't read from it independently. The easiest way to do this is for one object to hold a reference to both items having access to the input stream so that when a copy is made, we can remove the attribute from the other instance. So we create our parsed request instance from the wsgirequest constructor and hold a reference to it there. This is better than our new type holding a reference to wsgirequest because all the code for managing access will be temporary and we shouldn't pollute parsedrequest with this ugly history. Differential Revision: https://phab.mercurial-scm.org/D2770
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 10 Mar 2018 10:56:10 -0800
parents 2cdf47e14c30
children da4e2f87167d
files mercurial/hgweb/hgweb_mod.py mercurial/hgweb/hgwebdir_mod.py mercurial/hgweb/request.py
diffstat 3 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py	Sat Mar 10 11:03:45 2018 -0800
+++ b/mercurial/hgweb/hgweb_mod.py	Sat Mar 10 10:56:10 2018 -0800
@@ -304,7 +304,7 @@
                     yield r
 
     def _runwsgi(self, wsgireq, repo):
-        req = requestmod.parserequestfromenv(wsgireq.env)
+        req = wsgireq.req
         rctx = requestcontext(self, repo)
 
         # This state is global across all threads.
--- a/mercurial/hgweb/hgwebdir_mod.py	Sat Mar 10 11:03:45 2018 -0800
+++ b/mercurial/hgweb/hgwebdir_mod.py	Sat Mar 10 10:56:10 2018 -0800
@@ -287,6 +287,11 @@
                 real = repos.get(virtualrepo)
                 if real:
                     wsgireq.env['REPO_NAME'] = virtualrepo
+                    # We have to re-parse because of updated environment
+                    # variable.
+                    # TODO this is kind of hacky and we should have a better
+                    # way of doing this than with REPO_NAME side-effects.
+                    wsgireq.req = requestmod.parserequestfromenv(wsgireq.env)
                     try:
                         # ensure caller gets private copy of ui
                         repo = hg.repository(self.ui.copy(), real)
--- a/mercurial/hgweb/request.py	Sat Mar 10 11:03:45 2018 -0800
+++ b/mercurial/hgweb/request.py	Sat Mar 10 10:56:10 2018 -0800
@@ -254,6 +254,8 @@
         self.server_write = None
         self.headers = []
 
+        self.req = parserequestfromenv(wsgienv)
+
     def respond(self, status, type, filename=None, body=None):
         if not isinstance(type, str):
             type = pycompat.sysstr(type)