Commit 2d4b1f65 authored by Łukasz Nowak's avatar Łukasz Nowak

recurls: Use file to pass the data

Passing binary data via argument is dangrous.
parent 080f2313
......@@ -64,6 +64,7 @@ class Recurls(object):
response_header_file = tempfile.NamedTemporaryFile(delete=False).name
response_file = tempfile.NamedTemporaryFile(delete=False).name
hsts_file = tempfile.NamedTemporaryFile(delete=False).name
data_file = tempfile.NamedTemporaryFile(delete=False).name
command_list = [
self.curl,
'--disable',
......@@ -78,7 +79,11 @@ class Recurls(object):
'--write-out', '%{json}'
]
if data is not None:
command_list.extend(['--data-binary', data])
with open(data_file, 'wb') as fh:
if getattr(data, 'encode', None) is not None:
data = data.encode()
fh.write(data)
command_list.extend(['--data-binary', '@' + data_file])
if certificate is not None:
command_list.extend(['--cert', certificate])
if allow_redirects:
......@@ -146,6 +151,8 @@ class Recurls(object):
header, value = line.split(':', 1)
value = value.strip()
response.headers.add_header(header, value)
with open(response_file, 'rb') as fh:
response.raw_bytes = fh.read()
if response.headers.get('content-encoding') == 'gzip':
with gzip.GzipFile(response_file) as fh:
response.text = fh.read().decode()
......@@ -202,6 +209,7 @@ class Recurls(object):
os.unlink(request_header_file)
os.unlink(response_file)
os.unlink(hsts_file)
os.unlink(data_file)
# kwargs:
# params - Dictionary, list of tuples or bytes to send in the query
# string for the Request.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment