@@ -435,19 +435,64 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox
435435 timeout = TimeoutSauce (connect = timeout , read = timeout )
436436
437437 try :
438- resp = conn .urlopen (
439- method = request .method ,
440- url = url ,
441- body = request .body ,
442- headers = request .headers ,
443- redirect = False ,
444- assert_same_host = False ,
445- preload_content = False ,
446- decode_content = False ,
447- retries = self .max_retries ,
448- timeout = timeout ,
449- chunked = chunked
450- )
438+ if not chunked :
439+ resp = conn .urlopen (
440+ method = request .method ,
441+ url = url ,
442+ body = request .body ,
443+ headers = request .headers ,
444+ redirect = False ,
445+ assert_same_host = False ,
446+ preload_content = False ,
447+ decode_content = False ,
448+ retries = self .max_retries ,
449+ timeout = timeout
450+ )
451+
452+ # Send the request.
453+ else :
454+ if hasattr (conn , 'proxy_pool' ):
455+ conn = conn .proxy_pool
456+
457+ low_conn = conn ._get_conn (timeout = DEFAULT_POOL_TIMEOUT )
458+
459+ try :
460+ low_conn .putrequest (request .method ,
461+ url ,
462+ skip_accept_encoding = True )
463+
464+ for header , value in request .headers .items ():
465+ low_conn .putheader (header , value )
466+
467+ low_conn .endheaders ()
468+
469+ for i in request .body :
470+ low_conn .send (hex (len (i ))[2 :].encode ('utf-8' ))
471+ low_conn .send (b'\r \n ' )
472+ low_conn .send (i )
473+ low_conn .send (b'\r \n ' )
474+ low_conn .send (b'0\r \n \r \n ' )
475+
476+ # Receive the response from the server
477+ try :
478+ # For Python 2.7, use buffering of HTTP responses
479+ r = low_conn .getresponse (buffering = True )
480+ except TypeError :
481+ # For compatibility with Python 3.3+
482+ r = low_conn .getresponse ()
483+
484+ resp = HTTPResponse .from_httplib (
485+ r ,
486+ pool = conn ,
487+ connection = low_conn ,
488+ preload_content = False ,
489+ decode_content = False
490+ )
491+ except :
492+ # If we hit any problems here, clean up the connection.
493+ # Then, reraise so that we can handle the actual exception.
494+ low_conn .close ()
495+ raise
451496
452497 except (ProtocolError , socket .error ) as err :
453498 raise ConnectionError (err , request = request )
0 commit comments