diff options
Diffstat (limited to 'proxy.py')
-rw-r--r-- | proxy.py | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -24,7 +24,7 @@ class Fetcher(asynchat.async_chat): self.reader = reader self.proxy = ENDPOINTS(endpoint) self.url = url - self.header = self.header + self.header = header self.range = range self.start_time = time.time() @@ -37,7 +37,7 @@ class Fetcher(asynchat.async_chat): self.http_header = "" self.state = 0 #0=status, 1=header, 2=body self.create_socket(socket.AF_INET, socket.SOCK_STREAM) - self.connect(proxy) + self.connect(self.proxy) #XXXshould include original request headers def handle_connect (self): @@ -80,11 +80,12 @@ class Fetcher(asynchat.async_chat): class MultipleProxyReader(object): def __init__(self, channel, url, header, content_length): - print "MultipleProxyReader url=%s content_length=%s" % (url, content_length) self.channel = channel self.url = url self.header = header self.content_length = content_length + + print self self.header_sent = False self.fetch_pos = 0 @@ -137,10 +138,11 @@ class MultipleProxyReader(object): else: self.fetch_pos = self.content_length range = (start, self.fetch_pos-1) - Fetcher(self, ENDPOINTS[endpoint], self.url, self.header, range, self.content_length) + Fetcher(self, ENDPOINTS[endpoint], self.url, self.header, range) def find_next_data(self): - if not self.channel.writeable(): # request-side closed the connection + if self.channel.is_closed: + print self, "request side closed the connection" self.channel.close_when_done() #XXX terminate all running fetcher return False @@ -160,7 +162,7 @@ class MultipleProxyReader(object): return False def __str__(self): - return "<MultipleProxyReader >" + return "<MultipleProxyReader url=%s content_length=%s>" % (self.url, self.content_length) class HTTPChannel(asynchat.async_chat): def __init__(self, server, sock, addr): @@ -169,6 +171,10 @@ class HTTPChannel(asynchat.async_chat): self.set_terminator("\r\n\r\n") self.request = None self.data = StringIO.StringIO() + self.is_closed = False + + def handle_close(self): + self.is_closed = True def collect_incoming_data(self, data): self.data.write(data) |