comparison mercurial/httppeer.py @ 37555:930c433eb311

httppeer: always add x-hg* headers to Vary header Before, we manually updated the Vary header value for each header contributing to it. All X-Hg* headers are reserved for the Mercurial protocol and could have caching implications. So it makes sense to always add these headers to Vary. A test revealed that X-HgArgs-Post wasn't being added to Vary. This is only sent on POST requests. POST requests generally aren't cacheable. However, it is possible if the server sends the appropriate headers. Mercurial shouldn't be sending those headers. But let's not take any chances. Differential Revision: https://phab.mercurial-scm.org/D3240
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 10 Apr 2018 16:53:44 -0700
parents 301a1d2e8016
children b77aa48ba690
comparison
equal deleted inserted replaced
37554:301a1d2e8016 37555:930c433eb311
156 headers = args.pop('headers', {}) 156 headers = args.pop('headers', {})
157 157
158 ui.debug("sending %s command\n" % cmd) 158 ui.debug("sending %s command\n" % cmd)
159 q = [('cmd', cmd)] 159 q = [('cmd', cmd)]
160 headersize = 0 160 headersize = 0
161 varyheaders = []
162 # Important: don't use self.capable() here or else you end up 161 # Important: don't use self.capable() here or else you end up
163 # with infinite recursion when trying to look up capabilities 162 # with infinite recursion when trying to look up capabilities
164 # for the first time. 163 # for the first time.
165 postargsok = caps is not None and 'httppostargs' in caps 164 postargsok = caps is not None and 'httppostargs' in caps
166 165
192 # The headers can typically carry more data than the URL. 191 # The headers can typically carry more data than the URL.
193 encargs = urlreq.urlencode(sorted(args.items())) 192 encargs = urlreq.urlencode(sorted(args.items()))
194 for header, value in encodevalueinheaders(encargs, 'X-HgArg', 193 for header, value in encodevalueinheaders(encargs, 'X-HgArg',
195 headersize): 194 headersize):
196 headers[header] = value 195 headers[header] = value
197 varyheaders.append(header)
198 # Send arguments via query string (Mercurial <1.9). 196 # Send arguments via query string (Mercurial <1.9).
199 else: 197 else:
200 q += sorted(args.items()) 198 q += sorted(args.items())
201 199
202 qs = '?%s' % urlreq.urlencode(q) 200 qs = '?%s' % urlreq.urlencode(q)
236 protoheaders = encodevalueinheaders(' '.join(sorted(protoparams)), 234 protoheaders = encodevalueinheaders(' '.join(sorted(protoparams)),
237 'X-HgProto', 235 'X-HgProto',
238 headersize or 1024) 236 headersize or 1024)
239 for header, value in protoheaders: 237 for header, value in protoheaders:
240 headers[header] = value 238 headers[header] = value
239
240 varyheaders = []
241 for header in headers:
242 if header.lower().startswith(r'x-hg'):
241 varyheaders.append(header) 243 varyheaders.append(header)
242 244
243 if varyheaders: 245 if varyheaders:
244 headers[r'Vary'] = r','.join(varyheaders) 246 headers[r'Vary'] = r','.join(sorted(varyheaders))
245 247
246 req = requestbuilder(pycompat.strurl(cu), data, headers) 248 req = requestbuilder(pycompat.strurl(cu), data, headers)
247 249
248 if data is not None: 250 if data is not None:
249 ui.debug("sending %d bytes\n" % size) 251 ui.debug("sending %d bytes\n" % size)