def expect_response(self): if self.fp: self.fp.close() self.fp = None self.fp = self.sock.makefile('rb', 0) version, status, reason = self._read_status() if status != CONTINUE: self._read_status = lambda: (version, status, reason) self.begin() else: self.status = status self.reason = reason.strip() self.version = 11 if six.PY2: # Under py2, HTTPMessage.__init__ reads the headers # which advances fp self.msg = HTTPMessage(self.fp, 0) # immediately kill msg.fp to make sure it isn't read again self.msg.fp = None else: # py3 has a separate helper for it self.headers = self.msg = httplib.parse_headers(self.fp)