comparison mercurial/httppeer.py @ 32022:e5d7f99a3063

httppeer: don't send empty Vary request header As part of writing test-http-bad-server.t, I noticed that some requests include an empty Vary HTTP request header. The Vary HTTP request header indicates which headers should be taken into account when determining if a cached response can be used. It also accepts the special value of "*". The previous code unconditionally added a Vary header. This could lead to an empty header value. While I don't believe this violates the HTTP spec, this is weird and just wastes bytes. So this patch changes behavior to only send a Vary header when it has a value. Some low-level wire protocol byte reporting tests changed. In some cases, the exact point of data termination changed. However, the behavior being tested - that clients react when the connection is closed in the middle of an HTTP request line or header - remains unchanged.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 16 Apr 2017 11:28:02 -0700
parents 84569d2b3fb7
children a29580905771
comparison
equal deleted inserted replaced
32021:08e46fcb8637 32022:e5d7f99a3063
216 headersize or 1024) 216 headersize or 1024)
217 for header, value in protoheaders: 217 for header, value in protoheaders:
218 headers[header] = value 218 headers[header] = value
219 varyheaders.append(header) 219 varyheaders.append(header)
220 220
221 headers['Vary'] = ','.join(varyheaders) 221 if varyheaders:
222 headers['Vary'] = ','.join(varyheaders)
223
222 req = self.requestbuilder(cu, data, headers) 224 req = self.requestbuilder(cu, data, headers)
223 225
224 if data is not None: 226 if data is not None:
225 self.ui.debug("sending %s bytes\n" % size) 227 self.ui.debug("sending %s bytes\n" % size)
226 req.add_unredirected_header('Content-Length', '%d' % size) 228 req.add_unredirected_header('Content-Length', '%d' % size)