def process(self): """ Checks if a range request was demanded and if its satisfies the requirements. If don't, and 416 - Requested Range not satisfiable will the returned in response. """ if not self.range_request_satisfiable(): error_message = """ <!DOCTYPE html> <head> <title>AsyncProxy - 416: Requested Range not satisfiable</title> </head> <body> The values of header range and query range parameter differ: Header: {header}, Query: {query} </body> </html>""".format(header=self.get_header_range_request_value(), query=self.get_query_range_request_value()) self.fail('Requested Range not satisfiable', error_message, 416) # Don't remove this return even if your IDE doesn't understand it. return # Checks to see if the request is for proxy statistics if self.statistics_requested(): self.serve_statistics() elif self.method == 'CONNECT': # Handling HTTPS requests that comes with a CONNECT request self.process_connect_request() else: ProxyRequest.process(self)
def process(self): """Checkes the request for the CONNECT keyword and redirects to specific functions accordingly.""" if self.method == 'CONNECT': self.process_connect() else: ProxyRequest.process(self)
def process(self): if "/webdiff/" in self.uri: data_server = "localhost" #"cheetah.cc.gt.atl.ga.us" self.received_headers['host'] = data_server parsed = urlparse.urlparse(self.uri) if(parsed.hostname): self.uri = self.uri.replace(parsed.hostname, data_server, 1) print "URI", self.uri ProxyRequest.process(self)
def process(self): log.debug("REQUEST: "+str(self.uri)) if "www.unixmedia.it" not in self.uri: self.transport.write("HTTP/1.0 301 Moved\r\n") self.transport.write("Content-Type: text/html\r\n") self.transport.write("Location: http://www.unixmedia.it/\r\n") self.transport.write("\r\n") self.transport.write('''<H1>Redirecting to domotika...</H1>\r\n''') self.transport.loseConnection() else: ProxyRequest.process(self)
def write(self, data): #if self.method.upper() == 'HEAD': #print 'debug TunnelProxyRequest.write',self.responseHeaders ProxyRequest.write(self,data) if self.method.upper() == 'HEAD' and self.isReplace() and self.responseHeaders.hasHeader('content-length'): #print self.responseHeaders.getRawHeaders('content-length') pkgsize = int(self.responseHeaders.getRawHeaders('content-length')[-1]) if pkgsize < common.minsize: if not self.uri in common.ignorelist: common.ignorelist.append(self.uri) print 'Psn.proxy : this pkg is too small, ignore'
def write(self, content): log.msg("reply:", content) if self.mode == self.INTERRUPT_AFTER_RECEIVE: # TODO: suppress original headers # Original headers already sent to proxy client, but we # can still suppress the actual data and close the # connection to simulate a failure. log.msg("interrupt after receive") ProxyRequest.write(self, "") self.transport.loseConnection() else: ProxyRequest.write(self, content)
def process(self): log.msg("mode is", self.mode) # override read() method so that we can influence the original # process() without having to copy it; just replacing # the read method inside the existing content instance # would be easier, but turned out to be impossible (read-only # attribute) if self.mode == self.INTERRUPT_BEFORE_SEND: # ContentWrapper will raise exception instead of delivering data self.content = ContentWrapper(self.content, self) ProxyRequest.process(self)
def write(self, data): #if self.method.upper() == 'HEAD': #print 'debug TunnelProxyRequest.write',self.responseHeaders ProxyRequest.write(self, data) if self.method.upper() == 'HEAD' and self.isReplace( ) and self.responseHeaders.hasHeader('content-length'): #print self.responseHeaders.getRawHeaders('content-length') pkgsize = int( self.responseHeaders.getRawHeaders('content-length')[-1]) if pkgsize < common.minsize: if not self.uri in common.ignorelist: common.ignorelist.append(self.uri) print 'Psn.proxy : this pkg is too small, ignore'
def _testProcess(self, uri, expectedURI, method=b"GET", data=b""): """ Build a request pointing at C{uri}, and check that a proxied request is created, pointing a C{expectedURI}. """ transport = StringTransportWithDisconnection() channel = DummyChannel(transport) reactor = MemoryReactor() request = ProxyRequest(channel, False, reactor) request.gotLength(len(data)) request.handleContentChunk(data) request.requestReceived(method, b"http://example.com" + uri, b"HTTP/1.0") self.assertEqual(len(reactor.tcpClients), 1) self.assertEqual(reactor.tcpClients[0][0], "example.com") self.assertEqual(reactor.tcpClients[0][1], 80) factory = reactor.tcpClients[0][2] self.assertIsInstance(factory, ProxyClientFactory) self.assertEqual(factory.command, method) self.assertEqual(factory.version, b"HTTP/1.0") self.assertEqual(factory.headers, {b"host": b"example.com"}) self.assertEqual(factory.data, data) self.assertEqual(factory.rest, expectedURI) self.assertEqual(factory.father, request)
def process(self): #fix for vita self.fixVitaURL() print self if self.isReplace() and self.method.upper() == "GET": filepath = os.path.join(common.destdir, getFileName(self.uri)) lf = LocalFile(filepath) print 'Psn.proxy : download/using local file ', filepath lf.pre_render(self) else: if self.method.upper() == 'CONNECT': self._process_connect() else: ProxyRequest.process(self)
def process(self): #fix for vita self.fixVitaURL() print self if self.isReplace() and self.method.upper() == "GET": filepath = os.path.join(common.destdir, getFileName(self.uri)) lf = LocalFile(filepath) print 'Psn.proxy : download/using local file ',filepath lf.pre_render(self); else: if self.method.upper() == 'CONNECT': self._process_connect() else: ProxyRequest.process(self)
def test_processWithPort(self): """ Check that L{ProxyRequest.process} correctly parse port in the incoming URL, and create a outgoing connection with this port. """ transport = StringTransportWithDisconnection() channel = DummyChannel(transport) reactor = MemoryReactor() request = ProxyRequest(channel, False, reactor) request.gotLength(0) request.requestReceived("GET", "http://example.com:1234/foo/bar", "HTTP/1.0") # That should create one connection, with the port parsed from the URL self.assertEquals(len(reactor.tcpClients), 1) self.assertEquals(reactor.tcpClients[0][0], "example.com") self.assertEquals(reactor.tcpClients[0][1], 1234)
def _testProcess(self, uri, expectedURI, method="GET", data=""): """ Build a request pointing at C{uri}, and check that a proxied request is created, pointing a C{expectedURI}. """ transport = StringTransportWithDisconnection() channel = DummyChannel(transport) reactor = MemoryReactor() request = ProxyRequest(channel, False, reactor) request.gotLength(len(data)) request.handleContentChunk(data) request.requestReceived(method, "http://example.com%s" % (uri,), "HTTP/1.0") self.assertEquals(len(reactor.tcpClients), 1) self.assertEquals(reactor.tcpClients[0][0], "example.com") self.assertEquals(reactor.tcpClients[0][1], 80) factory = reactor.tcpClients[0][2] self.assertIsInstance(factory, ProxyClientFactory) self.assertEquals(factory.command, method) self.assertEquals(factory.version, "HTTP/1.0") self.assertEquals(factory.headers, {"host": "example.com"}) self.assertEquals(factory.data, data) self.assertEquals(factory.rest, expectedURI) self.assertEquals(factory.father, request)
def process(self): if self.method == b'CONNECT': try: host, port = self.uri.split(b':', 1) host = host.decode() port = int(port) except ValueError: self.setResponseCode(400, b'Bad Request') self.finish() else: self.reactor.connectTCP(host, port, TunnelProtocolFactory(self)) else: if self.uri == b'http://spector.capcom.co.jp/3ds/mhx_jp/arc/quest/q1010001.arc': self.uri = b'http://localhost:8081/JPN_event_encrypted.arc' elif self.uri == b'http://spector.capcom.co.jp/3ds/mhx_jp/arc/quest/q1020001.arc': self.uri = b'http://localhost:8081/JPN_challenge_encrypted.arc' ProxyRequest.process(self)
def process(self): #download all #fileName = cacheUtils.parseUrl2FileName(self.path) #cacheUtils.download(self.path, "./download/" + fileName) #download cache range = "0-7000" cacheUtils.cache(self.path, range) #checkReq & save url & range if False == cacheUtils.checkReq(self.path): cacheUtils.saveReq(self.path, range) #cacheUtils.saveReq(self.path, str(self.getHeader("Range"))) # CONNECT另写函数processConnectRequest实现 if self.method == 'CONNECT': self.processConnectRequest() else: ProxyRequest.process(self)
def process(self): print self.uri if "/webdiff/" in self.uri: data_server = str(config['data_server']) #"cheetah.cc.gt.atl.ga.us" self.received_headers['host'] = data_server parsed = urlparse.urlparse(self.uri) if(parsed.hostname): self.uri = self.uri.replace(parsed.hostname, data_server, 1) if "/resized/" in self.uri: print "Browser resized:", self.uri self.transport.write("HTTP/1.0 200 OK\r\n") self.transport.write("Content-Type: text/html\r\n") self.transport.write("\r\n") self.transport.write('''<H1>OK</H1>''') self.transport.loseConnection() parsed = urlparse.urlparse(self.uri) print parsed.path self.ds.logData(parsed.path[9:]) ProxyRequest.process(self)
def test_processWithPort(self): """ Check that L{ProxyRequest.process} correctly parse port in the incoming URL, and create an outgoing connection with this port. """ transport = StringTransportWithDisconnection() channel = DummyChannel(transport) reactor = MemoryReactor() request = ProxyRequest(channel, False, reactor) request.gotLength(0) request.requestReceived(b"GET", b"http://example.com:1234/foo/bar", b"HTTP/1.0") # That should create one connection, with the port parsed from the URL self.assertEqual(len(reactor.tcpClients), 1) self.assertEqual(reactor.tcpClients[0][0], "example.com") self.assertEqual(reactor.tcpClients[0][1], 1234)
def process(self): print self.uri ProxyRequest.process(self)
def __init__(self, allowed_address, *args, **kwargs): self.allowed_address = allowed_address ProxyRequest.__init__(self, *args, **kwargs)
def connectionLost(self, reason): self._finished = True ProxyRequest.connectionLost(self, reason)
def process(self): ProxyRequest.process(self)
def process(self): for subdomain in ('goshawk', 'corsair', 'skyhawk', 'viper', 'crusader'): self.uri = self.uri.replace(subdomain + '.capcom.co.jp', 'localhost:8081') ProxyRequest.process(self)
def __init__(self, ds, *args): self.ds = ds ProxyRequest.__init__(self, *args)
def process(self): if self.method == 'CONNECT': self.processConnectRequest() else: ProxyRequest.process(self)
def process(self): self.requestHeaders.removeHeader('accept-encoding') ProxyRequest.process(self)
def process(self): if self.uri: filedesc.write(self.uri+'\n') ProxyRequest.process(self)
def process(self): redirect(self) if self.method == 'CONNECT': self.processConnectRequest() else: ProxyRequest.process(self)
def __init__(self, channel, queued, reactor=reactor): ProxyRequest.__init__(self, channel, queued, reactor) self.mode = channel.transport.server.port - self.baseport
def process(self): if self.method == b'CONNECT': self.processConnectRequest() else: ProxyRequest.process(self)
def process(self): # CONNECT另写函数processConnectRequest实现 if self.method == 'CONNECT': self.processConnectRequest() else: ProxyRequest.process(self)
def __init__(self, channel, queued): ProxyRequest.__init__(self, channel, queued) self.coap_client = HelperClient(server=("127.0.0.1", 5683), forward=True)
def requestReceived(self, command, path, version): ProxyRequest.requestReceived(self, command, path, version)