mirror of https://github.com/scrapy/scrapy.git
Fix cookie lookup for dotless hosts and IP addresses (#7900)
This commit is contained in:
parent
a18d58d7b5
commit
63d5ce6272
|
|
@ -54,9 +54,9 @@ class CookieJar:
|
|||
if not IPV4_RE.search(req_host):
|
||||
hosts = potential_domain_matches(req_host)
|
||||
if "." not in req_host:
|
||||
hosts.append(req_host + ".local")
|
||||
hosts += potential_domain_matches(req_host + ".local")
|
||||
else:
|
||||
hosts = [req_host]
|
||||
hosts = [req_host, "." + req_host]
|
||||
|
||||
cookies = []
|
||||
for host in hosts:
|
||||
|
|
|
|||
|
|
@ -345,6 +345,30 @@ class TestCookiesMiddleware:
|
|||
assert "Cookie" in request.headers
|
||||
assert request.headers["Cookie"] == b"currencyCookie=USD"
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("url", "domain"),
|
||||
[
|
||||
("http://example-host/", "example-host.local"),
|
||||
("http://127.0.0.1/", "127.0.0.1"),
|
||||
pytest.param(
|
||||
"http://example-host/",
|
||||
"example-host",
|
||||
marks=pytest.mark.xfail(
|
||||
reason=(
|
||||
"http.cookiejar accepts a dotless domain for a dotless "
|
||||
"host but never returns the resulting cookie"
|
||||
)
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_explicit_local_domain(self, url: str, domain: str) -> None:
|
||||
request = Request(
|
||||
url, cookies=[{"name": "currencyCookie", "value": "USD", "domain": domain}]
|
||||
)
|
||||
assert self.mw.process_request(request) is None
|
||||
assert request.headers.get("Cookie") == b"currencyCookie=USD"
|
||||
|
||||
@pytest.mark.xfail(reason="Cookie header is not currently being processed")
|
||||
def test_keep_cookie_from_default_request_headers_middleware(self):
|
||||
DEFAULT_REQUEST_HEADERS = {"Cookie": "default=value; asdf=qwerty"}
|
||||
|
|
|
|||
Loading…
Reference in New Issue