diff options
-rw-r--r-- | proxy.py | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -1,5 +1,5 @@ #!/usr/bin/python -t -import pwd, os, sys, logging, logging.handlers, string +import pwd, os, sys, logging, logging.handlers, string, time import asynchat, asyncore, socket, httplib, urlparse try: import cStringIO as StringIO @@ -22,11 +22,10 @@ class Fetcher(asynchat.async_chat): self.reader = reader self.proxy = proxy self.url = url - self.header = self.header + self.header = header self.range = range self.start_time = time.time() - self.pos = range[0] asynchat.async_chat.__init__(self) self.set_terminator("\r\n") @@ -77,11 +76,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 @@ -124,11 +124,12 @@ class MultipleProxyReader(object): else: self.fetch_pos = self.content_length range = (start, self.fetch_pos-1) - Fetcher(self, ENDPOINTS[self.next_endpoint], self.url, self.header, range, self.content_length) + Fetcher(self, ENDPOINTS[self.next_endpoint], self.url, self.header, range) self.next_endpoint = (self.next_endpoint+1) % len(ENDPOINTS) 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 @@ -148,7 +149,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): @@ -157,6 +158,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) |