vcrpy
vcrpy copied to clipboard
filterheaders doesn't work for cookie / set-cookie
Tried to filter out cookies to prevent them from being recorded. Filtering on other headers works fine, but cookie
and set-cookie
keep appearing in the recordings.
my_vcr = vcr.VCR(
record_mode='all', path_transformer=VCR.ensure_suffix('.yaml'),
filter_headers=['Set-Cookie', 'Cookie'],
cassette_library_dir='dojo/unittests/vcr/jira/',
# filters headers doesn't seem to work for cookies, so use callbacks to filter cookies from being recorded
before_record_request=before_record_request,
before_record_response=before_record_response,
)
Also tried lowercase, different order, etc. In the end I implemented the customer request/response filters to remove the cookie headers. Am I misiing the correct way to filter cookies?
filter_headers
applies to request headers, so only Cookie
can be taken care of with it. Set-Cookie
on the other hand is a response header, and thus needs to be done with before_record_response
. This appears to work for me with pytest-vcr and pytest-recording:
def remove_set_cookie(response):
response["headers"].pop("Set-Cookie", None)
return response
@pytest.fixture(scope="module")
def vcr_config():
return {
"before_record_response": remove_set_cookie,
"filter_headers": ["Cookie"],
}