本文整理匯總了Python中twisted.web.proxy.Proxy方法的典型用法代碼示例。如果您正苦於以下問題:Python proxy.Proxy方法的具體用法?Python proxy.Proxy怎麽用?Python proxy.Proxy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.web.proxy
的用法示例。
在下文中一共展示了proxy.Proxy方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: dataReceived
# 需要導入模塊: from twisted.web import proxy [as 別名]
# 或者: from twisted.web.proxy import Proxy [as 別名]
def dataReceived(self, request):
try:
headers,content = Parser(request.decode())
url = content['resource']
host = headers['Host']
client_ip = str(self.transport.getPeer().host)
date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
useragent = headers['User-Agent']
result = Handler(date,request,host,url,client_ip,useragent)
if result == 'Safe':
return proxy.Proxy.dataReceived(self, request)
else:
return proxy.Proxy.dataReceived(self, b'GET http://house.proxy:8000/redirect HTTP/1.1\r\nHost: house.proxy:8000\r\n\r\n')
except Exception as e:
pass
示例2: requestDone
# 需要導入模塊: from twisted.web import proxy [as 別名]
# 或者: from twisted.web.proxy import Proxy [as 別名]
def requestDone(self, request):
if request.method == b'CONNECT' and self.connectedRemote is not None:
self.connectedRemote.connectedClient = self
self._handlingRequest = False
if self._savedTimeOut:
self.setTimeout(self._savedTimeOut)
data = b''.join(self._dataBuffer)
self._dataBuffer = []
self.setLineMode(data)
else:
proxy.Proxy.requestDone(self, request)
示例3: dataReceived
# 需要導入模塊: from twisted.web import proxy [as 別名]
# 或者: from twisted.web.proxy import Proxy [as 別名]
def dataReceived(self, data):
if self.connectedRemote is None:
proxy.Proxy.dataReceived(self, data)
else:
self.connectedRemote.transport.write(data)
示例4: process
# 需要導入模塊: from twisted.web import proxy [as 別名]
# 或者: from twisted.web.proxy import Proxy [as 別名]
def process(self):
host = None
port = None
parsed_uri = urlparse(self.uri)
self.uri = urlunparse(('', '', parsed_uri.path, parsed_uri.params, parsed_uri.query, parsed_uri.fragment)) or "/"
if self.has_request_modifiers():
self.run_request_modifiers()
if self.has_response_server():
self.serve_resource()
return
protocol = parsed_uri.scheme or 'http'
host = host or parsed_uri.netloc
port = port or parsed_uri.port or self.ports[protocol]
headers = self.getAllHeaders().copy()
if 'host' not in headers:
headers['host'] = host
if ':' in host:
host,_ = host.split(':')
self.content.seek(0, 0)
content = self.content.read()
clientFactory = InterceptingProxyClientFactory(self.method, self.uri, self.clientproto, headers, content, self)
self.reactor.connectTCP(host, port, clientFactory)
#Proxy(twisted.web.http.HTTPChannel)
示例5: __init__
# 需要導入模塊: from twisted.web import proxy [as 別名]
# 或者: from twisted.web.proxy import Proxy [as 別名]
def __init__(self, wordCounter):
self.wordCounter = wordCounter
proxy.Proxy.__init__(self)
示例6: buildProtocol
# 需要導入模塊: from twisted.web import proxy [as 別名]
# 或者: from twisted.web.proxy import Proxy [as 別名]
def buildProtocol(self, addr):
return Proxy()
示例7: main
# 需要導入模塊: from twisted.web import proxy [as 別名]
# 或者: from twisted.web.proxy import Proxy [as 別名]
def main():
http_port = reactor.listenTCP(PROXY_PORT, ProxyFactory())
def print_listening():
host = http_port.getHost()
print('Proxy server running at http://{}:{}'.format(
host.host, host.port))
reactor.callWhenRunning(print_listening)
reactor.run()