本文整理汇总了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()