summaryrefslogtreecommitdiff
path: root/proxy.py
diff options
context:
space:
mode:
authoryvesf <yvesf@aurora.xapek.org>2010-03-11 21:53:51 +0100
committeryvesf <yvesf@aurora.xapek.org>2010-03-11 21:53:51 +0100
commit170cc2e532974da7ae55e8b56f99c0b40ef17855 (patch)
tree163d09abf562865151623da7f4959f93001263b6 /proxy.py
parent18f6784874a89c924e6fda75cb6fafceecc69c82 (diff)
downloadmagicproxy-170cc2e532974da7ae55e8b56f99c0b40ef17855.tar.gz
magicproxy-170cc2e532974da7ae55e8b56f99c0b40ef17855.zip
Still not parallel
Diffstat (limited to 'proxy.py')
-rw-r--r--proxy.py25
1 files changed, 10 insertions, 15 deletions
diff --git a/proxy.py b/proxy.py
index a0f5c6b..d666df1 100644
--- a/proxy.py
+++ b/proxy.py
@@ -14,7 +14,7 @@ ENDPOINTS = [
#minimum entity size to start a paralel fetch
MINIMAL_SIZE = 524288
-BLOCKSIZE_FETCH = 131072
+BLOCKSIZE_FETCH = 524288
class Fetcher(asynchat.async_chat):
def __init__(self, reader, proxy, url, header, range, content_length):
@@ -53,7 +53,7 @@ class Fetcher(asynchat.async_chat):
self.pos += len(data)
if self.pos >= self.range[1]:
self.reader.finished()
- print "finished"
+ print "fetcher finished"
self.close_when_done()
elif self.state ==1: #header
self.http_header += data
@@ -86,7 +86,8 @@ class MultipleProxyReader(object):
self.blocks = dict()
self.next_endpoint = 0
- self.finished() #bad-named XXX
+ for i in range(0,len(ENDPOINTS)):
+ self.finished() #bad-named XXX
def handle_incoming_data(self, pos, data):
print "got body data at pos %s" % pos
@@ -116,7 +117,7 @@ class MultipleProxyReader(object):
def finished(self):
self.find_next_data()
- if self.fetch_pos != self.content_length:
+ if self.fetch_pos +1 <self.content_length:
print "start new fetcher"
start = self.fetch_pos
if self.fetch_pos+BLOCKSIZE_FETCH < self.content_length:
@@ -126,9 +127,6 @@ class MultipleProxyReader(object):
range = (start, self.fetch_pos-1)
Fetcher(self, ENDPOINTS[self.next_endpoint], self.url, self.header, range, self.content_length)
self.next_endpoint = (self.next_endpoint+1) % len(ENDPOINTS)
- else:
- #bin fertig
- self.channel.close_when_done()
def find_next_data(self):
print "expect at %s" % self.write_pos, self.blocks.keys()
@@ -139,12 +137,9 @@ class MultipleProxyReader(object):
print "Send %s bytes" % len(data)
self.find_next_data()
-class HTTPResponseProducer(object):
- def __init__(self, resp, amt=512):
- self.resp = resp
- self.amt = amt
- def more(self):
- self.resp.read(self.amt)
+ if self.write_pos + 1 >= self.content_length:
+ print "done"
+ self.channel.close_when_done()
class HTTPChannel(asynchat.async_chat):
def __init__(self, server, sock, addr):
@@ -213,7 +208,7 @@ class HTTPProxyServer(asyncore.dispatcher):
MultipleProxyReader(channel, url, header, content_length)
def _bypass_request(self, channel, method, url):
- print "_bypass request"
+ print "_bypass request hostname=%s port=%s path=%s" % (url.hostname, url.port or 80, url.path)
#XXX hier sollte nicht proxy gespielt werden sondern
#die daten 1-zu-1 durchgereicht werden.
#Weiterhin sollte sichergestellt werden, dass die requests
@@ -225,7 +220,7 @@ class HTTPProxyServer(asyncore.dispatcher):
channel.push("HTTP/1.0 200 OK\r\nX-Proxy: Magicproxy (superpower disabled)\r\n")
channel.push( "\r\n".join(map(lambda k: "%s: %s" % (k[0],k[1]), resp.getheaders())) )
channel.push("\r\n\r\n")
- channel.push_with_producer( HTTPResponseProducer(resp) )
+ channel.push(resp.read())
channel.close_when_done()
if __name__ == "__main__":