Commit 99ca803b authored by Vincent Ardisson's avatar Vincent Ardisson Committed by Vincent A

weboob/browser/browsers: when dumping HAR, add a key to tell binary data

For binary response, HAR allows base64 encoding so data is untouched.
But no such thing exists for binary posted data. Some generators write JSON
with the binary posted data as if it were latin-1 encoded text.
But when reading, what can we do? Think it's binary to encode back to latin-1?
Or think it's text?
HAR gives no answer, so we add a non-standard "x-binary" key to indicate
"text" is actually binary disguised with latin-1.
parent 8642772c
......@@ -286,6 +286,8 @@ class Browser(object):
'content': {
'mimeType': response.headers.get('Content-Type', ''),
'size': len(response.content),
# systematically use base64 to avoid more content alteration
# than there already is...
'encoding': "base64",
'text': base64.b64encode(response.content).decode('ascii'),
},
......@@ -316,7 +318,10 @@ class Browser(object):
if isinstance(request.body, str):
har_entry['request']['postData']['text'] = request.body
else:
# HAR format has no proper way to encode posted binary data!
har_entry['request']['postData']['text'] = request.body.decode('latin-1')
# add a non-standard key to indicate how should "text" be decoded.
har_entry['request']['postData']['x-binary'] = True
if request.headers.get('Content-Type') == 'application/x-www-form-urlencoded':
har_entry['request']['postData']['params'] = [
......
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