Mercurial > hg
comparison mercurial/keepalive.py @ 37665:83250442dc81
py3: use str variables to check keys in request header
The values in header are of str type.
Differential Revision: https://phab.mercurial-scm.org/D3326
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sat, 14 Apr 2018 02:02:11 +0530 |
parents | 192b7ad06932 |
children | e266e75d77dc |
comparison
equal
deleted
inserted
replaced
37664:483cafc3762a | 37665:83250442dc81 |
---|---|
316 headers = util.sortdict(self.parent.addheaders) | 316 headers = util.sortdict(self.parent.addheaders) |
317 headers.update(sorted(req.headers.items())) | 317 headers.update(sorted(req.headers.items())) |
318 headers.update(sorted(req.unredirected_hdrs.items())) | 318 headers.update(sorted(req.unredirected_hdrs.items())) |
319 headers = util.sortdict((n.lower(), v) for n, v in headers.items()) | 319 headers = util.sortdict((n.lower(), v) for n, v in headers.items()) |
320 skipheaders = {} | 320 skipheaders = {} |
321 for n in ('host', 'accept-encoding'): | 321 for n in (r'host', r'accept-encoding'): |
322 if n in headers: | 322 if n in headers: |
323 skipheaders['skip_' + n.replace('-', '_')] = 1 | 323 skipheaders[r'skip_' + n.replace(r'-', r'_')] = 1 |
324 try: | 324 try: |
325 if urllibcompat.hasdata(req): | 325 if urllibcompat.hasdata(req): |
326 data = urllibcompat.getdata(req) | 326 data = urllibcompat.getdata(req) |
327 h.putrequest( | 327 h.putrequest( |
328 req.get_method(), urllibcompat.getselector(req), | 328 req.get_method(), urllibcompat.getselector(req), |
329 **pycompat.strkwargs(skipheaders)) | 329 skipheaders) |
330 if r'content-type' not in headers: | 330 if r'content-type' not in headers: |
331 h.putheader(r'Content-type', | 331 h.putheader(r'Content-type', |
332 r'application/x-www-form-urlencoded') | 332 r'application/x-www-form-urlencoded') |
333 if r'content-length' not in headers: | 333 if r'content-length' not in headers: |
334 h.putheader(r'Content-length', r'%d' % len(data)) | 334 h.putheader(r'Content-length', r'%d' % len(data)) |
335 else: | 335 else: |
336 h.putrequest( | 336 h.putrequest( |
337 req.get_method(), urllibcompat.getselector(req), | 337 req.get_method(), urllibcompat.getselector(req), |
338 **pycompat.strkwargs(skipheaders)) | 338 skipheaders) |
339 except socket.error as err: | 339 except socket.error as err: |
340 raise urlerr.urlerror(err) | 340 raise urlerr.urlerror(err) |
341 for k, v in headers.items(): | 341 for k, v in headers.items(): |
342 h.putheader(k, v) | 342 h.putheader(k, v) |
343 h.endheaders() | 343 h.endheaders() |