hgweb: use our new request object for "style" parameter
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 10 Mar 2018 11:46:52 -0800
changeset 36869 1a1972b1a1ff
parent 36868 ec0af9c59270
child 36870 4e06e8336634
hgweb: use our new request object for "style" parameter The "style" parameter is kind of wonky because it is explicitly set and has lookups in random locations. Let's port it to qsparams first because it isn't straightforward. There is subtle change in behavior. But I don't think it is worth calling out in a BC. Our multidict's __getitem__ returns the last set value for a key, not the first. So if the query string set a variable multiple times, before we would get the first value and now we would get the last value. It makes no sense to specify these things multiple times. And I think last write wins is more sensible than first write wins. Differential Revision: https://phab.mercurial-scm.org/D2779
mercurial/hgweb/hgweb_mod.py
mercurial/hgweb/hgwebdir_mod.py
mercurial/hgweb/webcommands.py
mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/hgweb_mod.py	Sat Mar 10 12:35:38 2018 -0800
+++ b/mercurial/hgweb/hgweb_mod.py	Sat Mar 10 11:46:52 2018 -0800
@@ -53,9 +53,8 @@
 ))
 
 def getstyle(req, configfn, templatepath):
-    fromreq = req.form.get('style', [None])[0]
     styles = (
-        fromreq,
+        req.qsparams.get('style', None),
         configfn('web', 'style'),
         'paper',
     )
@@ -160,7 +159,7 @@
         # figure out which style to use
 
         vars = {}
-        styles, (style, mapfile) = getstyle(wsgireq, self.config,
+        styles, (style, mapfile) = getstyle(wsgireq.req, self.config,
                                             self.templatepath)
         if style == styles[0]:
             vars['style'] = style
@@ -337,7 +336,7 @@
             cmd = args.pop(0)
             style = cmd.rfind('-')
             if style != -1:
-                wsgireq.form['style'] = [cmd[:style]]
+                req.qsparams['style'] = cmd[:style]
                 cmd = cmd[style + 1:]
 
             # avoid accepting e.g. style parameter as command
@@ -355,7 +354,7 @@
 
             ua = req.headers.get('User-Agent', '')
             if cmd == 'rev' and 'mercurial' in ua:
-                wsgireq.form['style'] = ['raw']
+                req.qsparams['style'] = 'raw'
 
             if cmd == 'archive':
                 fn = wsgireq.form['node'][0]
@@ -389,7 +388,7 @@
             if cmd not in webcommands.__all__:
                 msg = 'no such method: %s' % cmd
                 raise ErrorResponse(HTTP_BAD_REQUEST, msg)
-            elif cmd == 'file' and 'raw' in wsgireq.form.get('style', []):
+            elif cmd == 'file' and req.qsparams.get('style') == 'raw':
                 rctx.ctype = ctype
                 content = webcommands.rawfile(rctx, wsgireq, tmpl)
             else:
--- a/mercurial/hgweb/hgwebdir_mod.py	Sat Mar 10 12:35:38 2018 -0800
+++ b/mercurial/hgweb/hgwebdir_mod.py	Sat Mar 10 11:46:52 2018 -0800
@@ -510,7 +510,7 @@
             url += '/'
 
         vars = {}
-        styles, (style, mapfile) = hgweb_mod.getstyle(wsgireq, config,
+        styles, (style, mapfile) = hgweb_mod.getstyle(wsgireq.req, config,
                                                       self.templatepath)
         if style == styles[0]:
             vars['style'] = style
--- a/mercurial/hgweb/webcommands.py	Sat Mar 10 12:35:38 2018 -0800
+++ b/mercurial/hgweb/webcommands.py	Sat Mar 10 11:46:52 2018 -0800
@@ -762,8 +762,8 @@
     basectx = ctx.p1()
 
     style = web.config('web', 'style')
-    if 'style' in req.form:
-        style = req.form['style'][0]
+    if 'style' in req.req.qsparams:
+        style = req.req.qsparams['style']
 
     diffs = webutil.diffs(web, tmpl, ctx, basectx, [path], style)
     if fctx is not None:
@@ -1011,8 +1011,8 @@
     entries = []
 
     diffstyle = web.config('web', 'style')
-    if 'style' in req.form:
-        diffstyle = req.form['style'][0]
+    if 'style' in req.req.qsparams:
+        diffstyle = req.req.qsparams['style']
 
     def diff(fctx, linerange=None):
         ctx = fctx.changectx()
--- a/mercurial/hgweb/webutil.py	Sat Mar 10 12:35:38 2018 -0800
+++ b/mercurial/hgweb/webutil.py	Sat Mar 10 11:46:52 2018 -0800
@@ -438,8 +438,8 @@
         basectx = ctx.p1()
 
     style = web.config('web', 'style')
-    if 'style' in req.form:
-        style = req.form['style'][0]
+    if 'style' in req.req.qsparams:
+        style = req.req.qsparams['style']
 
     diff = diffs(web, tmpl, ctx, basectx, None, style)