def handle(self, msock, msg, addr): packet=ProxyMessage() packet.decodeProxyMessage(msg) reqid=packet.reqid data=packet.data.decode('ascii') print('HTTP Proxy message from '+encodeAddress(addr)+':') print(data) parts=data.split(' ') print('parts: '+str(parts)) url=parts[1] print('url: '+str(url)) try: host=urlparse(url).netloc conn=httplib.HTTPConnection(host) conn.request('GET', url) resp=conn.getresponse() if resp.version==10: result=b"HTTP/1.0" elif resp.version==11: result=b"HTTP/1.1" else: result=b"HTTP/1.1" result=result+b' '+bytes(str(resp.status), 'ascii')+b' '+bytes(resp.reason, 'ascii')+b"\r\n" for key, value in resp.getheaders(): result=result+bytes(key, 'ascii')+b': '+bytes(value, 'ascii')+b"\r\n" result=result+b"\r\n" result=result+resp.read() except Exception as e: print(e) traceback.print_exc() result=b"HTTP/1.1 500 Error\r\n\r\n" # comp=bz2.compress(result) chunkSize=512 n=int(math.ceil(len(result)/chunkSize)) for i in range(n): start=chunkSize*i end=chunkSize*(i+1) print('sending '+str(i)) packet=ProxybackMessage() packet.createProxybackMessage(reqid, i, (i==n-1), result[start:end]) self.router.sendto(packet.msg, addr, service='httpProxyback') time.sleep(1)
def handle(self, msock, msg, addr): packet=ProxyMessage() packet.decodeProxyMessage(msg) reqid=packet.reqid data=packet.data.decode('ascii') print('HTTP Proxy message from '+encodeAddress(addr)+':') print(data) parts=data.split(' ') print('parts: '+str(parts)) url=parts[1] print('url: '+str(url)) try: print('connecting to '+str(urlparse(url).netloc)) parts=urlparse(url) print(parts) print(parts.username) print(parts.password) host=parts.hostname port=parts.port if not port: port=80 if parts.username and parts.password: auth=base64.b64encode(parts.username+':'+parts.password) else: auth=None headers={'Connection': 'close'} if auth: headers['Authentication']=auth print(headers) conn=httplib.HTTPConnection(host, port) conn.request('GET', url, headers=headers) resp=conn.getresponse() if resp.version==10: result=b"HTTP/1.0" elif resp.version==11: result=b"HTTP/1.1" else: result=b"HTTP/1.1" result=result+b' '+bytes(str(resp.status), 'ascii')+b' '+bytes(resp.reason, 'ascii')+b"\r\n" for key, value in resp.getheaders(): if key!='Connection': result=result+bytes(key, 'ascii')+b': '+bytes(value, 'ascii')+b"\r\n" result=result+b"Connection: close\r\n" result=result+b"Proxy-Connection: close\r\n" result=result+b"\r\n" result=result+resp.read() except Exception as e: print(e) traceback.print_exc() result=b"HTTP/1.1 500 Error\r\n\r\n" # comp=bz2.compress(result) chunkSize=512 n=int(math.ceil(len(result)/chunkSize)) for i in range(n): start=chunkSize*i end=chunkSize*(i+1) print('sending '+str(i)) packet=ProxybackMessage() packet.createProxybackMessage(reqid, i, (i==n-1), result[start:end]) self.router.sendto(packet.msg, addr, service='httpProxyback')
def processIn(self): data=self.inq.get() packet=ProxyMessage() packet.createProxyMessage(self.reqid, data) router.sendto(packet.msg, proxyAddr, service='httpProxy')
def processIn(self): data = self.inq.get() packet = ProxyMessage() packet.createProxyMessage(self.reqid, data) router.sendto(packet.msg, proxyAddr, service='httpProxy')