Skip to content

multiline headers are broken by vcrpy #947

@valumapps

Description

@valumapps

it seems vcrpy breaks headers which are split on multiple lines, while requests handles them without a problem.
For example, consider this response:

HTTP/1.1 200 OK
content-length: 2
link: <foo>; rel="foo"
link: <bar>; rel="bar"

{}

let's spawn a fake http server with it:

% respfile=$(mktemp)
% cat >| $respfile << EOF  
HTTP/1.1 200 OK 
content-length: 2
link: <foo>; rel="foo"
link: <bar>; rel="bar"

{}
EOF
% socat -U TCP-LISTEN:1234,fork OPEN:$respfile,rdonly=1

then let's call it with and without vcrpy to compare:

import requests
import vcr

URL = "http://localhost:1234"


def test_novcr() -> None:
    response = requests.get(URL)
    assert response.links.keys() == {"foo", "bar"}
    assert response.headers["link"] == '<foo>; rel="foo", <bar>; rel="bar"'


@vcr.use_cassette("dummy.yaml")
def test_yesvcr() -> None:
    response = requests.get(URL)
    assert response.links.keys() == {"foo", "bar"}
    assert response.headers["link"] == '<foo>; rel="foo", <bar>; rel="bar"'

and the result is:

% pytest --record-mode=rewrite vcrfail.py -xv
============================= test session starts ==============================
collected 2 items                                                              

vcrfail.py::test_novcr PASSED                                            [ 50%]
vcrfail.py::test_yesvcr FAILED                                           [100%]

=================================== FAILURES ===================================
_________________________________ test_yesvcr __________________________________

    @pytest.mark.vcr
    def test_yesvcr() -> None:
        response = requests.get(URL)
>       assert response.links.keys() == {"foo", "bar"}
E       AssertionError: assert dict_keys(['foo']) == {'bar', 'foo'}
E         
E         Full diff:
E         + dict_keys(['foo'])
E         - {
E         -     'bar',
E         -     'foo',
E         - }

vcrfail.py:16: AssertionError
=========================== short test summary info ============================
FAILED vcrfail.py::test_yesvcr - AssertionError: assert dict_keys(['foo']) == {'bar', 'foo'}
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
========================= 1 failed, 1 passed in 0.35s ==========================

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions