##// END OF EJS Templates
hgweb: ensure all wsgi environment values are str...
Gregory Szorc -
r36820:7fc80c98 default
parent child Browse files
Show More
@@ -159,7 +159,8 b' class requestcontext(object):'
159 urlbase = r'%s://%s%s' % (proto, req.env[r'SERVER_NAME'], port)
159 urlbase = r'%s://%s%s' % (proto, req.env[r'SERVER_NAME'], port)
160 logourl = self.config('web', 'logourl')
160 logourl = self.config('web', 'logourl')
161 logoimg = self.config('web', 'logoimg')
161 logoimg = self.config('web', 'logoimg')
162 staticurl = self.config('web', 'staticurl') or req.url + 'static/'
162 staticurl = (self.config('web', 'staticurl')
163 or pycompat.sysbytes(req.url) + 'static/')
163 if not staticurl.endswith('/'):
164 if not staticurl.endswith('/'):
164 staticurl += '/'
165 staticurl += '/'
165
166
@@ -182,7 +183,7 b' class requestcontext(object):'
182 if not self.reponame:
183 if not self.reponame:
183 self.reponame = (self.config('web', 'name', '')
184 self.reponame = (self.config('web', 'name', '')
184 or req.env.get('REPO_NAME')
185 or req.env.get('REPO_NAME')
185 or req.url.strip('/') or self.repo.root)
186 or req.url.strip(r'/') or self.repo.root)
186
187
187 def websubfilter(text):
188 def websubfilter(text):
188 return templatefilters.websub(text, self.websubtable)
189 return templatefilters.websub(text, self.websubtable)
@@ -190,7 +191,7 b' class requestcontext(object):'
190 # create the templater
191 # create the templater
191 # TODO: export all keywords: defaults = templatekw.keywords.copy()
192 # TODO: export all keywords: defaults = templatekw.keywords.copy()
192 defaults = {
193 defaults = {
193 'url': req.url,
194 'url': pycompat.sysbytes(req.url),
194 'logourl': logourl,
195 'logourl': logourl,
195 'logoimg': logoimg,
196 'logoimg': logoimg,
196 'staticurl': staticurl,
197 'staticurl': staticurl,
@@ -199,7 +200,7 b' class requestcontext(object):'
199 'encoding': encoding.encoding,
200 'encoding': encoding.encoding,
200 'motd': motd,
201 'motd': motd,
201 'sessionvars': sessionvars,
202 'sessionvars': sessionvars,
202 'pathdef': makebreadcrumb(req.url),
203 'pathdef': makebreadcrumb(pycompat.sysbytes(req.url)),
203 'style': style,
204 'style': style,
204 'nonce': self.nonce,
205 'nonce': self.nonce,
205 }
206 }
@@ -333,17 +334,17 b' class hgweb(object):'
333 # use SCRIPT_NAME, PATH_INFO and QUERY_STRING as well as our REPO_NAME
334 # use SCRIPT_NAME, PATH_INFO and QUERY_STRING as well as our REPO_NAME
334
335
335 req.url = req.env[r'SCRIPT_NAME']
336 req.url = req.env[r'SCRIPT_NAME']
336 if not req.url.endswith('/'):
337 if not req.url.endswith(r'/'):
337 req.url += '/'
338 req.url += r'/'
338 if req.env.get('REPO_NAME'):
339 if req.env.get('REPO_NAME'):
339 req.url += req.env[r'REPO_NAME'] + r'/'
340 req.url += req.env[r'REPO_NAME'] + r'/'
340
341
341 if r'PATH_INFO' in req.env:
342 if r'PATH_INFO' in req.env:
342 parts = req.env[r'PATH_INFO'].strip('/').split('/')
343 parts = req.env[r'PATH_INFO'].strip(r'/').split(r'/')
343 repo_parts = req.env.get(r'REPO_NAME', r'').split(r'/')
344 repo_parts = req.env.get(r'REPO_NAME', r'').split(r'/')
344 if parts[:len(repo_parts)] == repo_parts:
345 if parts[:len(repo_parts)] == repo_parts:
345 parts = parts[len(repo_parts):]
346 parts = parts[len(repo_parts):]
346 query = '/'.join(parts)
347 query = r'/'.join(parts)
347 else:
348 else:
348 query = req.env[r'QUERY_STRING'].partition(r'&')[0]
349 query = req.env[r'QUERY_STRING'].partition(r'&')[0]
349 query = query.partition(r';')[0]
350 query = query.partition(r';')[0]
@@ -364,7 +365,7 b' class hgweb(object):'
364
365
365 # translate user-visible url structure to internal structure
366 # translate user-visible url structure to internal structure
366
367
367 args = query.split('/', 2)
368 args = query.split(r'/', 2)
368 if 'cmd' not in req.form and args and args[0]:
369 if 'cmd' not in req.form and args and args[0]:
369 cmd = args.pop(0)
370 cmd = args.pop(0)
370 style = cmd.rfind('-')
371 style = cmd.rfind('-')
@@ -124,8 +124,8 b' class _httprequesthandler(httpservermod.'
124 env[r'SERVER_NAME'] = self.server.server_name
124 env[r'SERVER_NAME'] = self.server.server_name
125 env[r'SERVER_PORT'] = str(self.server.server_port)
125 env[r'SERVER_PORT'] = str(self.server.server_port)
126 env[r'REQUEST_URI'] = self.path
126 env[r'REQUEST_URI'] = self.path
127 env[r'SCRIPT_NAME'] = self.server.prefix
127 env[r'SCRIPT_NAME'] = pycompat.sysstr(self.server.prefix)
128 env[r'PATH_INFO'] = path[len(self.server.prefix):]
128 env[r'PATH_INFO'] = pycompat.sysstr(path[len(self.server.prefix):])
129 env[r'REMOTE_HOST'] = self.client_address[0]
129 env[r'REMOTE_HOST'] = self.client_address[0]
130 env[r'REMOTE_ADDR'] = self.client_address[0]
130 env[r'REMOTE_ADDR'] = self.client_address[0]
131 if query:
131 if query:
@@ -154,7 +154,7 b' class _httprequesthandler(httpservermod.'
154 env[hkey] = hval
154 env[hkey] = hval
155 env[r'SERVER_PROTOCOL'] = self.request_version
155 env[r'SERVER_PROTOCOL'] = self.request_version
156 env[r'wsgi.version'] = (1, 0)
156 env[r'wsgi.version'] = (1, 0)
157 env[r'wsgi.url_scheme'] = self.url_scheme
157 env[r'wsgi.url_scheme'] = pycompat.sysstr(self.url_scheme)
158 if env.get(r'HTTP_EXPECT', '').lower() == '100-continue':
158 if env.get(r'HTTP_EXPECT', '').lower() == '100-continue':
159 self.rfile = common.continuereader(self.rfile, self.wfile.write)
159 self.rfile = common.continuereader(self.rfile, self.wfile.write)
160
160
General Comments 0
You need to be logged in to leave comments. Login now