def test_getset_state(self): h = flow.ODictCaseless() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) req = flow.Request(c, "host", 22, "https", "GET", "/", h, "content") resp = flow.Response(req, 200, "msg", h.copy(), "content") state = resp._get_state() assert flow.Response._from_state(req, state) == resp resp2 = flow.Response(req, 220, "foo", h.copy(), "test") assert not resp == resp2 resp._load_state(resp2._get_state()) assert resp == resp2
def test_get_cookies_simple(self): h = flow.ODictCaseless() h["Set-Cookie"] = ["cookiename=cookievalue"] resp = flow.Response(None, (1, 1), 200, "OK", h, "content", None) result = resp.get_cookies() assert len(result)==1 assert "cookiename" in result assert result["cookiename"] == ("cookievalue", {})
def resp(self): f = self.req() headers = flow.ODictCaseless() headers["header_response"] = ["svalue"] f.response = flow.Response(f.request, (1, 1), 200, "message", headers, "content_response", None) return f
def tresp(req=None): if not req: req = treq() headers = flow.ODictCaseless() headers["header_response"] = ["svalue"] cert = certutils.SSLCert.from_der( file(test_data.path("data/dercert")).read()) return flow.Response(req, (1, 1), 200, "message", headers, "content_response", cert)
def test_get_cookies_no_value(self): h = flow.ODictCaseless() h["Set-Cookie"] = ["cookiename=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/"] resp = flow.Response(None, (1, 1), 200, "OK", h, "content", None) result = resp.get_cookies() assert len(result)==1 assert "cookiename" in result assert result["cookiename"][0] == "" assert len(result["cookiename"][1])==2
def test_simple(self): h = flow.Headers() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) req = flow.Request(c, "host", 22, "https", "GET", "/", h, "content") resp = flow.Response(req, 200, "msg", h.copy(), "content") assert resp._assemble() resp2 = resp.copy() assert resp2 == resp
def build_flow_response(self, req, status, status_text, headers, body): headers = ODictCaseless() for k,v in headers: headers[k] = v logging.info("%d %s (%d) [%s %s]: ", status, status_text, len(body), req.method, req.get_url()) resp = flow.Response(req, [1,1], status, status_text, headers, body, None) return resp
def test_get_cookies_with_parameters(self): h = flow.ODictCaseless() h["Set-Cookie"] = ["cookiename=cookievalue;domain=example.com;expires=Wed Oct 21 16:29:41 2015;path=/; HttpOnly"] resp = flow.Response(None, (1, 1), 200, "OK", h, "content", None) result = resp.get_cookies() assert len(result)==1 assert "cookiename" in result assert result["cookiename"][0] == "cookievalue" assert len(result["cookiename"][1])==4 assert result["cookiename"][1]["domain"]=="example.com" assert result["cookiename"][1]["expires"]=="Wed Oct 21 16:29:41 2015" assert result["cookiename"][1]["path"]=="/" assert result["cookiename"][1]["httponly"]==""
def test_simple(self): h = flow.ODictCaseless() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) req = flow.Request(c, "host", 22, "https", "GET", "/", h, "content") resp = flow.Response(req, 200, "msg", h.copy(), "content") assert resp._assemble() resp2 = resp.copy() assert resp2 == resp resp.content = None assert resp._assemble() resp.request.client_conn.close = True assert "connection: close" in resp._assemble()
def test_simple(self): h = flow.ODictCaseless() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) req = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content") resp = flow.Response(req, (1, 1), 200, "msg", h.copy(), "content", None) assert resp._assemble() assert resp.size() == len(resp._assemble()) resp2 = resp.copy() assert resp2 == resp resp.content = None assert resp._assemble() assert resp.size() == len(resp._assemble()) resp.content = flow.CONTENT_MISSING assert not resp._assemble()
def tresp(req=None): if not req: req = treq() headers = flow.Headers() headers["header_response"] = ["svalue"] return flow.Response(req, 200, "message", headers, "content_response")
def test_get_content_type(self): h = flow.ODictCaseless() h["Content-Type"] = ["text/plain"] resp = flow.Response(None, (1, 1), 200, "OK", h, "content", None) assert resp.get_content_type()=="text/plain"
def test_get_cookies_none(self): h = flow.ODictCaseless() resp = flow.Response(None, (1, 1), 200, "OK", h, "content", None) assert not resp.get_cookies()
def resp(self): q = self.req() headers = flow.Headers() headers["header_response"] = ["svalue"] return flow.Response(q, 200, "message", headers, "content_response")