Patchwork [6,of,8,V2] httppeer: assign Vary request header last

login
register
mail settings
Submitter Gregory Szorc
Date Nov. 29, 2016, 6:58 a.m.
Message ID <df89cc275198b7ebebf2.1480402703@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/17780/
State Accepted
Headers show

Comments

Gregory Szorc - Nov. 29, 2016, 6:58 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1480396071 28800
#      Mon Nov 28 21:07:51 2016 -0800
# Node ID df89cc275198b7ebebf2f9a477a1886c5fef2288
# Parent  36c296adbfabc1f7301dd6f94b5f4515e6a61b81
httppeer: assign Vary request header last

In preparation for adding another value to it in a subsequent patch.

While I was here, I added some empty lines because walls of text
are hard to read.
Augie Fackler - Dec. 2, 2016, 9:37 p.m.
On Mon, Nov 28, 2016 at 10:58:23PM -0800, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1480396071 28800
> #      Mon Nov 28 21:07:51 2016 -0800
> # Node ID df89cc275198b7ebebf2f9a477a1886c5fef2288
> # Parent  36c296adbfabc1f7301dd6f94b5f4515e6a61b81
> httppeer: assign Vary request header last

Took this one too, it's inevitable we'll want this cleanup.

>
> In preparation for adding another value to it in a subsequent patch.
>
> While I was here, I added some empty lines because walls of text
> are hard to read.
>
> diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
> --- a/mercurial/httppeer.py
> +++ b/mercurial/httppeer.py
> @@ -111,6 +111,7 @@ class httppeer(wireproto.wirepeer):
>          self.ui.debug("sending %s command\n" % cmd)
>          q = [('cmd', cmd)]
>          headersize = 0
> +        varyheaders = []
>          # Important: don't use self.capable() here or else you end up
>          # with infinite recursion when trying to look up capabilities
>          # for the first time.
> @@ -137,13 +138,11 @@ class httppeer(wireproto.wirepeer):
>                  headerfmt = 'X-HgArg-%s'
>                  contentlen = headersize - len(headerfmt % '000' + ': \r\n')
>                  headernum = 0
> -                varyheaders = []
>                  for i in xrange(0, len(encargs), contentlen):
>                      headernum += 1
>                      header = headerfmt % str(headernum)
>                      headers[header] = encargs[i:i + contentlen]
>                      varyheaders.append(header)
> -                headers['Vary'] = ','.join(varyheaders)
>              else:
>                  q += sorted(args.items())
>          qs = '?%s' % urlreq.urlencode(q)
> @@ -158,7 +157,10 @@ class httppeer(wireproto.wirepeer):
>              headers['X-HgHttp2'] = '1'
>          if data is not None and 'Content-Type' not in headers:
>              headers['Content-Type'] = 'application/mercurial-0.1'
> +
> +        headers['Vary'] = ','.join(varyheaders)
>          req = self.requestbuilder(cu, data, headers)
> +
>          if data is not None:
>              self.ui.debug("sending %s bytes\n" % size)
>              req.add_unredirected_header('Content-Length', '%d' % size)

Patch

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -111,6 +111,7 @@  class httppeer(wireproto.wirepeer):
         self.ui.debug("sending %s command\n" % cmd)
         q = [('cmd', cmd)]
         headersize = 0
+        varyheaders = []
         # Important: don't use self.capable() here or else you end up
         # with infinite recursion when trying to look up capabilities
         # for the first time.
@@ -137,13 +138,11 @@  class httppeer(wireproto.wirepeer):
                 headerfmt = 'X-HgArg-%s'
                 contentlen = headersize - len(headerfmt % '000' + ': \r\n')
                 headernum = 0
-                varyheaders = []
                 for i in xrange(0, len(encargs), contentlen):
                     headernum += 1
                     header = headerfmt % str(headernum)
                     headers[header] = encargs[i:i + contentlen]
                     varyheaders.append(header)
-                headers['Vary'] = ','.join(varyheaders)
             else:
                 q += sorted(args.items())
         qs = '?%s' % urlreq.urlencode(q)
@@ -158,7 +157,10 @@  class httppeer(wireproto.wirepeer):
             headers['X-HgHttp2'] = '1'
         if data is not None and 'Content-Type' not in headers:
             headers['Content-Type'] = 'application/mercurial-0.1'
+
+        headers['Vary'] = ','.join(varyheaders)
         req = self.requestbuilder(cu, data, headers)
+
         if data is not None:
             self.ui.debug("sending %s bytes\n" % size)
             req.add_unredirected_header('Content-Length', '%d' % size)