Esempio n. 1
0
 def test_anticache(self):
     h = utils.Headers()
     r = proxy.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
Esempio n. 2
0
    def test_simple(self):
        h = utils.Headers()
        h["test"] = ["test"]
        c = proxy.ClientConnect(("addr", 2222))
        req = proxy.Request(c, "host", 22, "https", "GET", "/", h, "content")
        resp = proxy.Response(req, 200, "msg", h.copy(), "content")
        assert resp.assemble()

        resp2 = resp.copy()
        assert resp2 == resp
Esempio n. 3
0
    def test_simple(self):
        h = utils.Headers()
        h["test"] = ["test"]
        c = proxy.ClientConnect(("addr", 2222))
        r = proxy.Request(c, "host", 22, "https", "GET", "/", h, "content")
        u = r.url()
        assert r.set_url(u)
        assert not r.set_url("")
        assert r.url() == u
        assert r.assemble()

        r2 = r.copy()
        assert r == r2
Esempio n. 4
0
    def test_getset_state(self):
        h = utils.Headers()
        h["test"] = ["test"]
        c = proxy.ClientConnect(("addr", 2222))
        r = proxy.Request(c, "host", 22, "https", "GET", "/", h, "content")
        req = proxy.Request(c, "host", 22, "https", "GET", "/", h, "content")
        resp = proxy.Response(req, 200, "msg", h.copy(), "content")

        state = resp.get_state()
        assert proxy.Response.from_state(req, state) == resp

        resp2 = proxy.Response(req, 220, "foo", h.copy(), "test")
        assert not resp == resp2
        resp.load_state(resp2.get_state())
        assert resp == resp2
Esempio n. 5
0
    def test_getset_state(self):
        h = utils.Headers()
        h["test"] = ["test"]
        c = proxy.ClientConnect(("addr", 2222))
        r = proxy.Request(c, "host", 22, "https", "GET", "/", h, "content")
        state = r.get_state()
        assert proxy.Request.from_state(state) == r

        r.client_conn = None
        state = r.get_state()
        assert proxy.Request.from_state(state) == r

        r2 = proxy.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
Esempio n. 6
0
def tresp(req=None):
    if not req:
        req = treq()
    headers = utils.Headers()
    headers["header_response"] = ["svalue"]
    return proxy.Response(req, 200, "message", headers, "content_response")
Esempio n. 7
0
 def resp(self):
     q = self.req()
     headers = utils.Headers()
     headers["header_response"] = ["svalue"]
     return proxy.Response(q, 200, "message", headers, "content_response")
Esempio n. 8
0
 def req(self):
     conn = proxy.ClientConnect(("one", 2222))
     headers = utils.Headers()
     headers["header"] = ["qvalue"]
     return proxy.Request(conn, "host", 80, "http", "GET", "/path", headers,
                          "content_request")