summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryvesf <yvesf@aurora.xapek.org>2010-03-11 16:42:56 +0100
committeryvesf <yvesf@aurora.xapek.org>2010-03-11 16:42:56 +0100
commita7a05acc71a3c0cdc78468170b0af4afb81ec565 (patch)
tree2b1dbb08e2003f20f6d45001b458b06676c61cab
parent59a601f64206a9784889dcefcb103580753f9d86 (diff)
downloadmagicproxy-a7a05acc71a3c0cdc78468170b0af4afb81ec565.tar.gz
magicproxy-a7a05acc71a3c0cdc78468170b0af4afb81ec565.zip
cleanup, still missing the relevant feature
-rw-r--r--proxy.py33
1 files changed, 23 insertions, 10 deletions
diff --git a/proxy.py b/proxy.py
index b721134..585b58b 100644
--- a/proxy.py
+++ b/proxy.py
@@ -1,7 +1,6 @@
#!/usr/bin/python -t
+import pwd, os, sys, logging, logging.handlers, string
import asynchat, asyncore, socket, httplib, urlparse
-import pwd, os, sys, logging, logging.handlers
-import string
try:
import cStringIO as StringIO
except ImportError:
@@ -9,10 +8,12 @@ except ImportError:
endpoints = {
- {'host':'10.1.0.1', 'port':'8080', 'speed':220, 'name':'Yves Proxy'},
- {'host':'10.3.0.99', 'port':'8080', 'speed':340, 'name':'Thomas Proxy'},
+ {'host':'10.1.0.1', 'port':8080, 'speed':220, 'name':'Proxy 10.1'},
+ {'host':'10.2.2.11', 'port':8081, 'speed':340, 'name':'Proxy 10.2'},
+ {'host':'10.3.0.99', 'port':8080, 'speed':340, 'name':'Proxy 10.3'},
}
+
class HTTPResponseProducer(object):
def __init__(self, resp, amt=512):
self.resp = resp
@@ -27,7 +28,6 @@ class HTTPChannel(asynchat.async_chat):
self.set_terminator("\r\n\r\n")
self.request = None
self.data = StringIO.StringIO()
- self.shutdown = 0
def collect_incoming_data(self, data):
self.data.write(data)
@@ -64,8 +64,9 @@ class HTTPProxyServer(asyncore.dispatcher):
def handle_request(self, channel, method, path):
url = urlparse.urlparse(path)
print method, path
- if method != "GET":
- return self._do_standard_proxy(channel, method, url)
+ if method != "GET" or url.query != "":
+ #do not handle non-GET or GET with Query (?foo=bla) requests
+ return self._bypass_request(channel, method, url)
#check for content-length header with a HEAD request
conn = httplib.HTTPConnection(url.hostname, url.port or 80)
@@ -73,18 +74,29 @@ class HTTPProxyServer(asyncore.dispatcher):
resp = conn.getresponse()
content_length = filter(lambda it: it[0] == "content-length", resp.getheaders())
if len( content_length ) == 0:
- return self._do_standard_proxy(channel, method, url)
+ # no content length given, bypass this request
+ return self._bypass_request(channel, method, url)
else:
content_length = content_length[0][1]
+ if content_length < 524288:
+ # do not handle requests smaller than 512kb
+ return self._bypass_request(channel, method, url)
+
print "Content-Length: %s" % (content_length)
- return self._do_standard_proxy(channel, method, url)
+ # XXX an dieser stelle muss de request aufgeteilt werden
+ return self._bypass_request(channel, method, url)
#print "do some magic for " +str(url)
#channel.push("HTTP/1.0 200 OK\r\nX-Proxy: Magicproxy (request handled in boost mode)\r\n")
#channel.close_when_done()
- def _do_standard_proxy(self, channel, method, url):
+ def _bypass_request(self, channel, method, url):
+ #XXX hier sollte nicht proxy gespielt werden sondern
+ #die daten 1-zu-1 durchgereicht werden.
+ #Weiterhin sollte sichergestellt werden, dass die requests
+ #zu Host X1 immer über Proxy Y1 geroutet werden
+ # etwa proxy=proxies[ stuff(hostname) % len(proxies) ]
conn = httplib.HTTPConnection(url.hostname, url.port or 80)
conn.request(method, url.path)
resp = conn.getresponse()
@@ -92,6 +104,7 @@ class HTTPProxyServer(asyncore.dispatcher):
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.close_when_done()
if __name__ == "__main__":
proxy = HTTPProxyServer()