Skip to content

Cannot record header to file #715

@dwt

Description

@dwt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions