def read_headers(self): header_type = "request" if self.type == "server" else "response" line = self._read_line() if header_type == "request": while line == "": line = self._read_line() lines = [] for _ in xrange(MAX_NUM_HEADERS): lines.append(line) line = self._read_line() if line == "": break else: raise HTTPSyntaxError("Too many headers") headers = HTTPHeaders.parse(header_type, lines) # self._expect_continue = False # if type_ == 'request' and auto_continue and \ # headers.get_single('Expect') == '100-continue': # self._expect_continue = True self._has_body = True if header_type == "request": if not headers.get_chunked() and not headers.get_content_length(): self._has_body = False else: if self._sent_method.upper() == b"HEAD": self._has_body = False if headers.code >= 100 and headers.code < 200: self._has_body = False if headers.code == 204 or headers.code == 304: self._has_body = False self._chunked = headers.get_chunked() self._content_length = headers.get_content_length() self._content_type = headers.get_single("Content-Type") return headers
def error_close(self): if self.type == "server" and not self._headers_sent: response = HTTPHeaders.response(500) response.set(b"Connection", b"close") self.send_headers(response) self.close()