From b97c5ca89ed619c1463bd9932d77f34ec59e7171 Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Thu, 17 Mar 2016 16:59:54 +0100 Subject: Limit HTTP chunk size to 900000 bytes --- tools/certtools.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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: -- cgit v1.1