def __init__(self, body="", headers=None, status=None, **kwds): if headers: if isinstance(headers, dict): headers = HTTPHeaders(headers) elif isinstance(headers, list): headers = HTTPHeaders.from_lists(headers) else: headers = HTTPHeaders() for k, v in kwds.items(): # More headers headers.add(k, v) self.headers = headers self.status = status or 200 self._body = body or "" if not self.headers.get("Content-Length"): self.headers["Content-Length"] = str(len(self.body))
def test_http_header_dict(http): hdict = HTTPHeaders(http.header) assert len(hdict) == 3 assert hdict['Content_Encoding'] assert hdict.get('ContentType') is None hdict.add('Server', 'pyzest.com') hdict.add('Content-Encoding', 'deflate') and hdict['Content-Encoding'] assert hdict.getall('Content_Encoding') == ['gzip', 'deflate'] hdict = HTTPHeaders.from_lines(http.header_line) assert hdict['Connection'] == 'keep-alive' HTTPHeaders.from_lines(http.b_header_line) wsgi_header = hdict.to_wsgi_list() assert isinstance(wsgi_header, list) assert len(wsgi_header) == 2