Skip to content
Snippets Groups Projects
Commit 60a9d81c authored by ale's avatar ale
Browse files

throttle HTTPS connections too (doh!)

parent 1b5131fe
Branches
No related tags found
No related merge requests found
...@@ -63,19 +63,17 @@ def set_rate_limit(kbps): ...@@ -63,19 +63,17 @@ def set_rate_limit(kbps):
_bucket = TokenBucket(2 * bps, bps) _bucket = TokenBucket(2 * bps, bps)
class ThrottledHTTPConnection(httplib.HTTPConnection): class ThrottledHTTPConnectionMixin(object):
BLOCK_SIZE = 4096 BLOCK_SIZE = 4096
def send(self, str): def throttled_send(self, str):
if self.sock is None: if self.sock is None:
if self.auto_open: if self.auto_open:
self.connect() self.connect()
else: else:
raise httplib.NotConnected() raise httplib.NotConnected()
if self.debuglevel > 0:
print "send:", repr(str)
try: try:
tot = len(str) tot = len(str)
for off in xrange(0, tot, self.BLOCK_SIZE): for off in xrange(0, tot, self.BLOCK_SIZE):
...@@ -93,9 +91,29 @@ class ThrottledHTTPConnection(httplib.HTTPConnection): ...@@ -93,9 +91,29 @@ class ThrottledHTTPConnection(httplib.HTTPConnection):
raise raise
class ThrottledHTTPSConnection(httplib.HTTPSConnection,
ThrottledHTTPConnectionMixin):
def send(self, str):
return self.throttled_send(str)
class ThrottledHTTPConnection(httplib.HTTPConnection,
ThrottledHTTPConnectionMixin):
def send(self, str):
return self.throttled_send(str)
class ThrottledHTTPHandler(urllib2.HTTPHandler): class ThrottledHTTPHandler(urllib2.HTTPHandler):
def http_open(self, req): def http_open(self, req):
return self.do_open(ThrottledHTTPConnection, req) return self.do_open(ThrottledHTTPConnection, req)
class ThrottledHTTPSHandler(urllib2.HTTPSHandler):
def https_open(self, req):
return self.do_open(ThrottledHTTPSConnection, req)
...@@ -68,7 +68,8 @@ class Uploader(threading.Thread): ...@@ -68,7 +68,8 @@ class Uploader(threading.Thread):
self.queue = Queue.Queue(100) self.queue = Queue.Queue(100)
self.db_path = db_path self.db_path = db_path
self.stats = stats.Stats(state_path) self.stats = stats.Stats(state_path)
self.opener = urllib2.build_opener(throttle.ThrottledHTTPHandler) self.opener = urllib2.build_opener(throttle.ThrottledHTTPHandler,
throttle.ThrottledHTTPSHandler)
user_agent = 'djrandom_client/%s (%s %s Python/%s)' % ( user_agent = 'djrandom_client/%s (%s %s Python/%s)' % (
version.VERSION, platform.system(), platform.machine(), version.VERSION, platform.system(), platform.machine(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment