329 headers = util.sortdict(self.parent.addheaders) |
329 headers = util.sortdict(self.parent.addheaders) |
330 headers.update(sorted(req.headers.items())) |
330 headers.update(sorted(req.headers.items())) |
331 headers.update(sorted(req.unredirected_hdrs.items())) |
331 headers.update(sorted(req.unredirected_hdrs.items())) |
332 headers = util.sortdict((n.lower(), v) for n, v in headers.items()) |
332 headers = util.sortdict((n.lower(), v) for n, v in headers.items()) |
333 skipheaders = {} |
333 skipheaders = {} |
334 for n in (r'host', r'accept-encoding'): |
334 for n in ('host', 'accept-encoding'): |
335 if n in headers: |
335 if n in headers: |
336 skipheaders[r'skip_' + n.replace(r'-', r'_')] = 1 |
336 skipheaders['skip_' + n.replace('-', '_')] = 1 |
337 try: |
337 try: |
338 if urllibcompat.hasdata(req): |
338 if urllibcompat.hasdata(req): |
339 data = urllibcompat.getdata(req) |
339 data = urllibcompat.getdata(req) |
340 h.putrequest( |
340 h.putrequest( |
341 req.get_method(), |
341 req.get_method(), |
342 urllibcompat.getselector(req), |
342 urllibcompat.getselector(req), |
343 **skipheaders |
343 **skipheaders |
344 ) |
344 ) |
345 if r'content-type' not in headers: |
345 if 'content-type' not in headers: |
346 h.putheader( |
346 h.putheader( |
347 r'Content-type', r'application/x-www-form-urlencoded' |
347 'Content-type', 'application/x-www-form-urlencoded' |
348 ) |
348 ) |
349 if r'content-length' not in headers: |
349 if 'content-length' not in headers: |
350 h.putheader(r'Content-length', r'%d' % len(data)) |
350 h.putheader('Content-length', '%d' % len(data)) |
351 else: |
351 else: |
352 h.putrequest( |
352 h.putrequest( |
353 req.get_method(), |
353 req.get_method(), |
354 urllibcompat.getselector(req), |
354 urllibcompat.getselector(req), |
355 **skipheaders |
355 **skipheaders |
399 # modification from socket.py |
399 # modification from socket.py |
400 |
400 |
401 def __init__(self, sock, debuglevel=0, strict=0, method=None): |
401 def __init__(self, sock, debuglevel=0, strict=0, method=None): |
402 extrakw = {} |
402 extrakw = {} |
403 if not pycompat.ispy3: |
403 if not pycompat.ispy3: |
404 extrakw[r'strict'] = True |
404 extrakw['strict'] = True |
405 extrakw[r'buffering'] = True |
405 extrakw['buffering'] = True |
406 httplib.HTTPResponse.__init__( |
406 httplib.HTTPResponse.__init__( |
407 self, sock, debuglevel=debuglevel, method=method, **extrakw |
407 self, sock, debuglevel=debuglevel, method=method, **extrakw |
408 ) |
408 ) |
409 self.fileno = sock.fileno |
409 self.fileno = sock.fileno |
410 self.code = None |
410 self.code = None |