##// 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 if args:
351 if args:
352 wsgireq.form['file'] = args
352 wsgireq.form['file'] = args
353
353
354 ua = wsgireq.env.get('HTTP_USER_AGENT', '')
354 ua = req.headers.get('User-Agent', '')
355 if cmd == 'rev' and 'mercurial' in ua:
355 if cmd == 'rev' and 'mercurial' in ua:
356 wsgireq.form['style'] = ['raw']
356 wsgireq.form['style'] = ['raw']
357
357
@@ -11,6 +11,7 b' from __future__ import absolute_import'
11 import cgi
11 import cgi
12 import errno
12 import errno
13 import socket
13 import socket
14 import wsgiref.headers as wsgiheaders
14 #import wsgiref.validate
15 #import wsgiref.validate
15
16
16 from .common import (
17 from .common import (
@@ -85,6 +86,9 b' class parsedrequest(object):'
85 querystringlist = attr.ib()
86 querystringlist = attr.ib()
86 # Dict of query string arguments. Values are lists with at least 1 item.
87 # Dict of query string arguments. Values are lists with at least 1 item.
87 querystringdict = attr.ib()
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 def parserequestfromenv(env):
93 def parserequestfromenv(env):
90 """Parse URL components from environment variables.
94 """Parse URL components from environment variables.
@@ -186,6 +190,16 b' def parserequestfromenv(env):'
186 else:
190 else:
187 querystringdict[k] = [v]
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 return parsedrequest(url=fullurl, baseurl=baseurl,
203 return parsedrequest(url=fullurl, baseurl=baseurl,
190 advertisedurl=advertisedfullurl,
204 advertisedurl=advertisedfullurl,
191 advertisedbaseurl=advertisedbaseurl,
205 advertisedbaseurl=advertisedbaseurl,
@@ -194,7 +208,8 b' def parserequestfromenv(env):'
194 havepathinfo='PATH_INFO' in env,
208 havepathinfo='PATH_INFO' in env,
195 querystring=querystring,
209 querystring=querystring,
196 querystringlist=querystringlist,
210 querystringlist=querystringlist,
197 querystringdict=querystringdict)
211 querystringdict=querystringdict,
212 headers=headers)
198
213
199 class wsgirequest(object):
214 class wsgirequest(object):
200 """Higher-level API for a WSGI request.
215 """Higher-level API for a WSGI request.
General Comments 0
You need to be logged in to leave comments. Login now