def __init__(self, *args, **kwargs): self.host = '' self.realhost = '' self.rp = None self.cache = None self.key = None ProxyClientFactory.__init__(self,*args,**kwargs)
def __init__(self, command, rest, version, headers, data, request): """ Override ProxyClientFactory.__init__ to return HBProxyClient """ ProxyClientFactory.__init__(self, command, rest, version, headers, data, request)
def __init__(self, uuid="NotDefinedYet", *args, **kwargs): self.uuid = uuid self.logDebug("__init__", "Called") self.host = '' self.realhost = '' self.rp = None self.cache = None self.key = None ProxyClientFactory.__init__(self, *args, **kwargs)
def __init__(self, command, rest, version, headers, data, father, resource): self.resource = resource ProxyClientFactory.__init__(self, command=command, rest=rest, version=version, headers=headers, data=data, father=father)
def test_buildProtocol(self): """ L{ProxyClientFactory.buildProtocol} should produce a L{ProxyClient} with the same values of attributes (with updates on the headers). """ factory = ProxyClientFactory("GET", "/foo", "HTTP/1.0", {"accept": "text/html"}, "Some data", None) proto = factory.buildProtocol(None) self.assertIsInstance(proto, ProxyClient) self.assertEquals(proto.command, "GET") self.assertEquals(proto.rest, "/foo") self.assertEquals(proto.data, "Some data") self.assertEquals(proto.headers, {"accept": "text/html", "connection": "close"})
def test_connectionFailed(self): """ Check that L{ProxyClientFactory.clientConnectionFailed} produces a B{501} response to the parent request. """ request = DummyRequest(["foo"]) factory = ProxyClientFactory("GET", "/foo", "HTTP/1.0", {"accept": "text/html"}, "", request) factory.clientConnectionFailed(None, None) self.assertEquals(request.responseCode, 501) self.assertEquals(request.responseMessage, "Gateway error") self.assertEquals(list(request.responseHeaders.getAllRawHeaders()), [("Content-Type", ["text/html"])]) self.assertEquals("".join(request.written), "<H1>Could not connect</H1>") self.assertEquals(request.finished, 1)
def test_buildProtocol(self): """ L{ProxyClientFactory.buildProtocol} should produce a L{ProxyClient} with the same values of attributes (with updates on the headers). """ factory = ProxyClientFactory(b'GET', b'/foo', b'HTTP/1.0', {b"accept": b"text/html"}, b'Some data', None) proto = factory.buildProtocol(None) self.assertIsInstance(proto, ProxyClient) self.assertEqual(proto.command, b'GET') self.assertEqual(proto.rest, b'/foo') self.assertEqual(proto.data, b'Some data') self.assertEqual(proto.headers, {b"accept": b"text/html", b"connection": b"close"})
def test_connectionFailed(self): """ Check that L{ProxyClientFactory.clientConnectionFailed} produces a B{501} response to the parent request. """ request = DummyRequest(['foo']) factory = ProxyClientFactory('GET', '/foo', 'HTTP/1.0', {"accept": "text/html"}, '', request) factory.clientConnectionFailed(None, None) self.assertEquals(request.responseCode, 501) self.assertEquals(request.responseMessage, "Gateway error") self.assertEquals(list(request.responseHeaders.getAllRawHeaders()), [("Content-Type", ["text/html"])]) self.assertEquals(''.join(request.written), "<H1>Could not connect</H1>") self.assertEquals(request.finished, 1)
def test_connectionFailed(self): """ Check that L{ProxyClientFactory.clientConnectionFailed} produces a B{501} response to the parent request. """ serverTransport = StringTransportWithDisconnection() channel = DummyChannel(serverTransport) parent = DummyParent(channel) serverTransport.protocol = channel factory = ProxyClientFactory('GET', '/foo', 'HTTP/1.0', {"accept": "text/html"}, '', parent) factory.clientConnectionFailed(None, None) self.assertEquals(serverTransport.value(), "HTTP/1.0 501 Gateway error\r\n" "Content-Type: text/html\r\n\r\n" "<H1>Could not connect</H1>") self.assertIsInstance(channel.lostReason, ConnectionDone)
def buildProtocol(self, address): if self.father.allowed_address != address.host: log.msg("Host {0} is not allowed!".format(address.host), system="address_filter") self.father.setResponseCode(403, "Host not allowed!") self.father.finish() return protocol.Protocol() log.msg("Host {0} is allowed!".format(address.host), system="address_filter") return ProxyClientFactory.buildProtocol(self, address)
def test_connectionFailed(self): """ Check that L{ProxyClientFactory.clientConnectionFailed} produces a B{501} response to the parent request. """ serverTransport = StringTransportWithDisconnection() channel = DummyChannel(serverTransport) parent = DummyParent(channel) serverTransport.protocol = channel factory = ProxyClientFactory('GET', '/foo', 'HTTP/1.0', {"accept": "text/html"}, '', parent) factory.clientConnectionFailed(None, None) self.assertEquals( serverTransport.value(), "HTTP/1.0 501 Gateway error\r\n" "Content-Type: text/html\r\n\r\n" "<H1>Could not connect</H1>") self.assertIsInstance(channel.lostReason, ConnectionDone)
def test_connectionFailed(self): """ Check that L{ProxyClientFactory.clientConnectionFailed} produces a B{501} response to the parent request. """ request = DummyRequest([b"foo"]) factory = ProxyClientFactory(b"GET", b"/foo", b"HTTP/1.0", {b"accept": b"text/html"}, "", request) factory.clientConnectionFailed(None, None) self.assertEqual(request.responseCode, 501) self.assertEqual(request.responseMessage, b"Gateway error") self.assertEqual( list(request.responseHeaders.getAllRawHeaders()), [(b"Content-Type", [b"text/html"])], ) self.assertEqual(b"".join(request.written), b"<H1>Could not connect</H1>") self.assertEqual(request.finished, 1)
def test_connectionFailed(self): """ Check that L{ProxyClientFactory.clientConnectionFailed} produces a B{501} response to the parent request. """ request = DummyRequest([b'foo']) factory = ProxyClientFactory(b'GET', b'/foo', b'HTTP/1.0', {b"accept": b"text/html"}, '', request) factory.clientConnectionFailed(None, None) self.assertEqual(request.responseCode, 501) self.assertEqual(request.responseMessage, b"Gateway error") self.assertEqual( list(request.responseHeaders.getAllRawHeaders()), [(b"Content-Type", [b"text/html"])]) self.assertEqual( b''.join(request.written), b"<H1>Could not connect</H1>") self.assertEqual(request.finished, 1)
def __init__(self, *args, **kwargs): ProxyClientFactory.__init__(self, *args, **kwargs) self.done = Deferred()
def __init__(self, command, rest, version, headers, data, father): ProxyClientFactory.__init__(self, command, rest, version, headers, data, father)
def buildProtocol(self, addr): self.d.callback(True) return ProxyClientFactory.buildProtocol(self, addr)