Exemple #1
0
 def __init__(self, *args, **kwargs):
     HTTPConnection.__init__(self, *args, **kwargs)
     self._original_response_cls = self.response_class
     # We'd ideally hook into httplib's states, but they're all
     # __mangled_vars so we use our own state var.  This variable is set
     # when we receive an early response from the server.  If this value is
     # set to True, any calls to send() are noops.  This value is reset to
     # false every time _send_request is called.  This is to workaround the
     # fact that py2.6 (and only py2.6) has a separate send() call for the
     # body in _send_request, as opposed to endheaders(), which is where the
     # body is sent in all versions > 2.6.
     self._response_received = False
Exemple #2
0
    def _tunnel(self):
        # Works around a bug in py26 which is fixed in later versions of
        # python. Bug involves hitting an infinite loop if readline() returns
        # nothing as opposed to just ``\r\n``.
        # As much as I don't like having if py2: <foo> code blocks, this seems
        # the cleanest way to handle this workaround.  Fortunately, the
        # difference from py26 to py3 is very minimal.  We're essentially
        # just overriding the while loop.
        if sys.version_info[:2] != (2, 6):
            return HTTPConnection._tunnel(self)

        # Otherwise we workaround the issue.
        self._set_hostport(self._tunnel_host, self._tunnel_port)
        self.send("CONNECT %s:%d HTTP/1.0\r\n" % (self.host, self.port))
        for header, value in self._tunnel_headers.iteritems():
            self.send("%s: %s\r\n" % (header, value))
        self.send("\r\n")
        response = self.response_class(self.sock, strict = self.strict,
                                       method = self._method)
        (version, code, message) = response._read_status()

        if code != 200:
            self.close()
            raise socket.error("Tunnel connection failed: %d %s" %
                               (code, message.strip()))
        while True:
            line = response.fp.readline()
            if not line:
                break
            if line in (b'\r\n', b'\n', b''):
                break
Exemple #3
0
 def _send_request(self, method, url, body, headers):
     self._response_received = False
     if headers.get('Expect', '') == '100-continue':
         self._expect_header_set = True
     else:
         self._expect_header_set = False
         self.response_class = self._original_response_cls
     rval = HTTPConnection._send_request(
         self, method, url, body, headers)
     self._expect_header_set = False
     return rval
Exemple #4
0
 def send(self, str):
     if self._response_received:
         logger.debug("send() called, but reseponse already received. "
                      "Not sending data.")
         return
     return HTTPConnection.send(self, str)