Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/integration/test_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def test_ignore_httpbin(tmpdir, httpbin):
assert len(cass) == 1


def test_ignore_httpbin_regex(tmpdir, httpbin):
with overridden_dns({"httpbin.org": "127.0.0.1"}):
cass_file = str(tmpdir.join("filter_qs.yaml"))
with vcr.use_cassette(cass_file, ignore_hosts=[r"h\w*bin.+"]) as cass:
urlopen(f"http://httpbin.org:{httpbin.port}/")
assert len(cass) == 0


def test_ignore_localhost_and_httpbin(tmpdir, httpbin):
with overridden_dns({"httpbin.org": "127.0.0.1"}):
cass_file = str(tmpdir.join("filter_qs.yaml"))
Expand Down
5 changes: 4 additions & 1 deletion vcr/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import inspect
import os
import types
import re
from collections import abc as collections_abc
from pathlib import Path

Expand Down Expand Up @@ -231,8 +232,10 @@ def before_record_request(request):

@staticmethod
def _build_ignore_hosts(hosts_to_ignore):
hosts_to_ignore_re = re.compile("(" + ")|(".join(hosts_to_ignore) + ")")

def filter_ignored_hosts(request):
if hasattr(request, "host") and request.host in hosts_to_ignore:
if hasattr(request, "host") and bool(hosts_to_ignore_re.match(request.host)):
return
return request

Expand Down