##// END OF EJS Templates
hgweb: parse and store HTTP request headers...
Gregory Szorc -
r36832:f9078c6c default
parent child Browse files
Show More
@@ -351,7 +351,7 b' class hgweb(object):'
351 351 if args:
352 352 wsgireq.form['file'] = args
353 353
354 ua = wsgireq.env.get('HTTP_USER_AGENT', '')
354 ua = req.headers.get('User-Agent', '')
355 355 if cmd == 'rev' and 'mercurial' in ua:
356 356 wsgireq.form['style'] = ['raw']
357 357
@@ -11,6 +11,7 b' from __future__ import absolute_import'
11 11 import cgi
12 12 import errno
13 13 import socket
14 import wsgiref.headers as wsgiheaders
14 15 #import wsgiref.validate
15 16
16 17 from .common import (
@@ -85,6 +86,9 b' class parsedrequest(object):'
85 86 querystringlist = attr.ib()
86 87 # Dict of query string arguments. Values are lists with at least 1 item.
87 88 querystringdict = attr.ib()
89 # wsgiref.headers.Headers instance. Operates like a dict with case
90 # insensitive keys.
91 headers = attr.ib()
88 92
89 93 def parserequestfromenv(env):
90 94 """Parse URL components from environment variables.
@@ -186,6 +190,16 b' def parserequestfromenv(env):'
186 190 else:
187 191 querystringdict[k] = [v]
188 192
193 # HTTP_* keys contain HTTP request headers. The Headers structure should
194 # perform case normalization for us. We just rewrite underscore to dash
195 # so keys match what likely went over the wire.
196 headers = []
197 for k, v in env.iteritems():
198 if k.startswith('HTTP_'):
199 headers.append((k[len('HTTP_'):].replace('_', '-'), v))
200
201 headers = wsgiheaders.Headers(headers)
202
189 203 return parsedrequest(url=fullurl, baseurl=baseurl,
190 204 advertisedurl=advertisedfullurl,
191 205 advertisedbaseurl=advertisedbaseurl,
@@ -194,7 +208,8 b' def parserequestfromenv(env):'
194 208 havepathinfo='PATH_INFO' in env,
195 209 querystring=querystring,
196 210 querystringlist=querystringlist,
197 querystringdict=querystringdict)
211 querystringdict=querystringdict,
212 headers=headers)
198 213
199 214 class wsgirequest(object):
200 215 """Higher-level API for a WSGI request.
General Comments 0
You need to be logged in to leave comments. Login now