def response_start(self, status_code: bytes, status_phrase: bytes, res_hdrs: RawHeaderListType) -> None: "Start a response. Must only be called once per response." res_hdrs = [i for i in res_hdrs if not i[0].lower() in hop_by_hop_hdrs] try: body_len = int(get_header(res_hdrs, b"content-length").pop(0)) except (IndexError, ValueError): body_len = None if body_len is not None: delimit = Delimiters.COUNTED res_hdrs.append((b"Connection", b"keep-alive")) elif self.req_version == b"1.1": delimit = Delimiters.CHUNKED res_hdrs.append((b"Transfer-Encoding", b"chunked")) else: delimit = Delimiters.CLOSE res_hdrs.append((b"Connection", b"close")) self.http_conn.output_start( b"HTTP/1.1 %s %s" % (status_code, status_phrase), res_hdrs, delimit)
def test_get_header(self): self.assertEqual(get_header(self.hdrs, "a"), ["a1", "a2", "a3", "a4"]) self.assertEqual(get_header(self.hdrs, "b"), ["b1", "b2"]) self.assertEqual(get_header(self.hdrs, "c"), ["c1"])
def test_get_header(self): self.assertEqual(get_header(hdrs, 'a'), ['a1', 'a2', 'a3', 'a4']) self.assertEqual(get_header(hdrs, 'b'), ['b1', 'b2']) self.assertEqual(get_header(hdrs, 'c'), ['c1'])
def test_get_header(self): self.assertEqual(get_header(self.hdrs, b'a'), [b'a1', b'a2', b'a3', b'a4']) self.assertEqual(get_header(self.hdrs, b'b'), [b'b1', b'b2']) self.assertEqual(get_header(self.hdrs, b'c'), [b'c1'])