-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy1.py
More file actions
29 lines (23 loc) · 760 Bytes
/
proxy1.py
File metadata and controls
29 lines (23 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import time
import urllib2
from twisted.protocols import basic
class ProxyProtocol(basic.LineReceiver):
def lineReceived(self, url):
if not url.startswith('http://'):
return
start = time.time()
print 'fetching', url
connection = urllib2.urlopen(url)
data = connection.read()
print 'fetched', url,
self.transport.write(data)
self.transport.loseConnection()
print 'in', time.time() - start
from twisted.internet import protocol
class ProxyFactory(protocol.ServerFactory):
protocol = ProxyProtocol
from twisted.internet import reactor, endpoints
endpoint = endpoints.TCP4ServerEndpoint(reactor, 8000)
factory = ProxyFactory()
endpoint.listen(factory)
reactor.run()