summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2016-03-17 16:59:54 +0100
committerMagnus Ahltorp <map@kth.se>2016-03-17 16:59:54 +0100
commitb97c5ca89ed619c1463bd9932d77f34ec59e7171 (patch)
treeb50a5e72128406a958a93755b744a24f328240cf
parentb1d0d1bf04c7cb49d1e80eaac73886cf4ad5b1dc (diff)
Limit HTTP chunk size to 900000 bytes
-rw-r--r--tools/certtools.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/tools/certtools.py b/tools/certtools.py
index 023bc1e..1523c97 100644
--- a/tools/certtools.py
+++ b/tools/certtools.py
@@ -273,16 +273,23 @@ def http_request(url, data=None, key=None, verifynode=None, publickeydir=".", pa
with requests.sessions.Session() as session:
return http_request_session(url, data=data, key=key, verifynode=verifynode, publickeydir=publickeydir, params=params, session=session)
+def chunk_generator(data, maxsize):
+ while len(data):
+ yield data[:maxsize]
+ data = data[maxsize:]
+
def http_request_session(url, data=None, key=None, verifynode=None, publickeydir=".", params=None, session=None):
(keyname, keyfile) = key
privatekey = get_eckey_from_file(keyfile)
sk = ecdsa.SigningKey.from_der(privatekey)
if data == None:
method = "GET"
+ chunked_data = None
else:
method = "POST"
+ chunked_data = chunk_generator(data, 900000)
assert(params == None)
- req = requests.Request(method, url, params=params, data=data)
+ req = requests.Request(method, url, params=params, data=chunked_data)
prepared_req = session.prepare_request(req)
parsed_url = urlparse.urlparse(prepared_req.url)
if data == None: