Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot record header to file #715

Closed
dwt opened this issue May 17, 2024 · 2 comments
Closed

Cannot record header to file #715

dwt opened this issue May 17, 2024 · 2 comments
Labels

Comments

@dwt
Copy link

dwt commented May 17, 2024

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.

@TheJacobWalters
Copy link
Contributor

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?

@markstory
Copy link
Member

If you have time and interest a pull request would be greatly appreciated @TheJacobWalters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

3 participants