summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves <yvesf-git@xapek.org>2010-03-12 21:07:08 +0100
committerYves <yvesf-git@xapek.org>2010-03-12 21:07:08 +0100
commitfc2385d1b3ced7f34b23bcce0bc48c6764fe12fa (patch)
tree7a75cb006a086edcd3452095590b75b5bb7aea24
parentb35fa3d8fe84b625756a3eee9518617998682244 (diff)
downloadmagicproxy-fc2385d1b3ced7f34b23bcce0bc48c6764fe12fa.tar.gz
magicproxy-fc2385d1b3ced7f34b23bcce0bc48c6764fe12fa.zip
hmmm
-rw-r--r--proxy.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/proxy.py b/proxy.py
index 0fbb199..7c873b9 100644
--- a/proxy.py
+++ b/proxy.py
@@ -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)