def treq(conn=None): if not conn: conn = flow.ClientConnect(("address", 22)) headers = flow.Headers() headers["header"] = ["qvalue"] return flow.Request(conn, "host", 80, "http", "GET", "/path", headers, "content")
def test_match_re(self): h = flow.Headers() h.add("one", "uno") h.add("two", "due") h.add("two", "tre") assert h.match_re("uno") assert h.match_re("two: due") assert not h.match_re("nonono")
def test_anticache(self): h = flow.Headers() r = flow.Request(None, "host", 22, "https", "GET", "/", h, "content") h["if-modified-since"] = ["test"] h["if-none-match"] = ["test"] r.anticache() assert not "if-modified-since" in r.headers assert not "if-none-match" in r.headers
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 test_simple(self): h = flow.Headers() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) r = flow.Request(c, "host", 22, "https", "GET", "/", h, "content") u = r.get_url() assert r.set_url(u) assert not r.set_url("") assert r.get_url() == u assert r._assemble() r2 = r.copy() assert r == r2
def test_getset_state(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") 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_all(self): d = Dummy() h = flow.Headers() s = cStringIO.StringIO("testing") assert proxy.read_http_body(s, d, h, False, None) == "" h["content-length"] = ["foo"] s = cStringIO.StringIO("testing") libpry.raises(proxy.ProxyError, proxy.read_http_body, s, d, h, False, None) h["content-length"] = [5] s = cStringIO.StringIO("testing") assert len(proxy.read_http_body(s, d, h, False, None)) == 5 s = cStringIO.StringIO("testing") libpry.raises(proxy.ProxyError, proxy.read_http_body, s, d, h, False, 4) h = flow.Headers() s = cStringIO.StringIO("testing") assert len(proxy.read_http_body(s, d, h, True, 4)) == 4 s = cStringIO.StringIO("testing") assert len(proxy.read_http_body(s, d, h, True, 100)) == 7
def test_getset_state(self): h = flow.Headers() h["test"] = ["test"] c = flow.ClientConnect(("addr", 2222)) r = flow.Request(c, "host", 22, "https", "GET", "/", h, "content") state = r._get_state() assert flow.Request._from_state(state) == r r.client_conn = None state = r._get_state() assert flow.Request._from_state(state) == r r2 = flow.Request(c, "testing", 20, "http", "PUT", "/foo", h, "test") assert not r == r2 r._load_state(r2._get_state()) assert r == r2 r2.client_conn = None r._load_state(r2._get_state()) assert not r.client_conn
def setUp(self): self.hd = flow.Headers()
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 resp(self): q = self.req() headers = flow.Headers() headers["header_response"] = ["svalue"] return flow.Response(q, 200, "message", headers, "content_response")
def req(self): conn = flow.ClientConnect(("one", 2222)) headers = flow.Headers() headers["header"] = ["qvalue"] return flow.Request(conn, "host", 80, "http", "GET", "/path", headers, "content_request")