From 8505f1972a5ed811e96cde5b08a47fbc162926fa Mon Sep 17 00:00:00 2001 From: yvesf Date: Fri, 12 Mar 2010 20:19:15 +0100 Subject: schnell schnell --- proxy.py | 86 +++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 41 insertions(+), 45 deletions(-) diff --git a/proxy.py b/proxy.py index 0c4ea06..d4cf892 100644 --- a/proxy.py +++ b/proxy.py @@ -10,20 +10,20 @@ except ImportError: ENDPOINTS = [ ('10.2.2.11', 8888), ('10.3.1.2', 8888), + ('10.1.1.156', 8888), ] #minimum entity size to start a paralel fetch -MINIMAL_SIZE = 524288 -BLOCKSIZE_FETCH = 1048576 - +KB = 1024 +MINIMAL_SIZE = 512 * KB +BLOCKSIZE_FETCH = 2048 * KB class Fetcher(asynchat.async_chat): - def __init__(self, reader, proxy, url, header, range, content_length): - print "Fetcher using proxy=%s for url=%s range=%s content_length=%s" % (proxy, url, range, content_length) + def __init__(self, reader, proxy, url, header, range): self.reader = reader self.proxy = proxy self.url = url + self.header = self.header self.range = range - self.content_length = content_length self.pos = range[0] asynchat.async_chat.__init__(self) @@ -36,24 +36,19 @@ class Fetcher(asynchat.async_chat): #XXXshould include original request headers def handle_connect (self): - print "handle_connect" - self.debug_send("GET http://%s:%s%s HTTP/1.0\r\n" % ( self.url.hostname, self.url.port or 80, self.url.path )) - self.debug_send("Range: bytes=%s-%s\r\n" % (self.range[0], self.range[1])) - self.debug_send("\r\n") - print "sent request" + print self,"handle_connect" + self.send("GET http://%s:%s%s HTTP/1.0\r\n" % ( self.url.hostname, self.url.port or 80, self.url.path )) + #XXX self.header + self.send("Range: bytes=%s-%s\r\n" % (self.range[0], self.range[1])) + self.send("\r\n") - def debug_send(self, data): - print "SEND", data - self.send(data) - def collect_incoming_data(self, data): - if self.state==2:#body - print "read at %s - range_start=%s range_end=%s" % (self.pos, self.range[0], self.range[1]) + if self.state==2: #body self.reader.handle_incoming_data(self.pos, data) self.pos += len(data) if self.pos >= self.range[1]: self.reader.finished() - print "fetcher finished" + print self, "finished" self.close_when_done() elif self.state ==1: #header self.http_header += data @@ -64,13 +59,16 @@ class Fetcher(asynchat.async_chat): if self.state == 0: self.state = 1 self.set_terminator("\r\n\r\n") - print "got status line" + #print "got status line" elif self.state == 1: self.state = 2 self.set_terminator(None) - print "header ends now" + print self, "header ends now" self.reader.handle_incoming_http_header(self.http_header) + def __str__(self): + return "= self.content_length: - print "done" + print self, "done" self.channel.close_when_done() return r + def __str__(self): + return "" + class HTTPChannel(asynchat.async_chat): def __init__(self, server, sock, addr): asynchat.async_chat.__init__(self, sock) @@ -199,16 +199,12 @@ class HTTPProxyServer(asyncore.dispatcher): if len( content_length ) == 0: # no content length given, bypass this request print "missing content-length, bypass" - return self._bypass_request(channel, "GET", url) + self._bypass_request(channel, "GET", url) else: content_length = int(content_length[0][1]) - - #if content_length < MINIMAL_SIZE: - # return self._bypass_request(channel, "GET", url) - - ##XXX - header = (("foo", "bla")) - MultipleProxyReader(channel, url, header, content_length) + ##XXX + header = (("foo", "bla")) + MultipleProxyReader(channel, url, header, content_length) def _bypass_request(self, channel, method, url): print "_bypass request hostname=%s port=%s path=%s" % (url.hostname, url.port or 80, url.path) -- cgit v1.2.1