Cannot record header to file
dwt opened this issue · 2 comments
Describe the bug
When recording a request that contains a location header, that header is not there anymore, when replaying that request.
Additional context
It seems the code in _add_from_file() doesn't seem to restore headers, while the code in _dump() does seem to save them.
Version of responses
0.25.0
Steps to Reproduce
>>> import responses
>>> responses.post(url="fnord", status=201, headers=dict(Location='fnord'))
<Response(url='fnord' status=201 content_type='text/plain' headers='{"Location": "fnord"}')>
>>> responses.registered()
[<Response(url='fnord' status=201 content_type='text/plain' headers='{"Location": "fnord"}')>, <Response(url='fnord' status=201 content_type='text/plain' headers='{"Location": "fnord"}')>]
>>> import responses._recorder
>>> import yaml
>>> responses._recorder._dump(responses.registered(), open('/dev/stdout', 'w'), yaml.dump)
responses:
- response:
auto_calculate_content_length: false
body: ''
content_type: text/plain
headers:
Location: fnord
method: POST
status: 201
url: fnord
>>> responses._recorder._dump(responses.registered(), open('/tmp/dump', 'w'), yaml.dump)
>>> responses._add_from_file(file_path="/tmp/dump")
>>> responses.registered()
[<Response(url='fnord' status=201 content_type='text/plain' headers='{"Location": "fnord"}')>, <Response(url='fnord' status=201 content_type='text/plain' headers='null')>]
Expected Result
Interestingly this does save the location headers, while they are not saved in my application where I discovered this. Still when loading the dump, the headers are ignored.
I'd expect the location header to survive the save / restore.
Actual Result
Location header gets stripped by the replay from file.
I was able to reproduce this. If the maintainers determine this to be a bug that should be fixed. Could I try and fix it?
If you have time and interest a pull request would be greatly appreciated @TheJacobWalters