Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about requestCookies=[] #115

Merged
merged 1 commit into from
Jul 25, 2023
Merged
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
17 changes: 16 additions & 1 deletion scrapy_zyte_api/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,23 @@ def _set_http_request_cookies_from_request(
):
api_params.setdefault("experimental", {})
if "requestCookies" in api_params["experimental"]:
if api_params["experimental"]["requestCookies"] is False:
request_cookies = api_params["experimental"]["requestCookies"]
if request_cookies is False:
del api_params["experimental"]["requestCookies"]
elif not request_cookies and isinstance(request_cookies, list):
logger.warning(
(
"Request %(request)r is overriding automatic request "
"cookie mapping by explicitly setting "
"experimental.requestCookies to []. If this was your "
"intention, please use False instead of []. Otherwise, "
"stop defining experimental.requestCookies in your "
"request to let automatic mapping work."
),
{
"request": request,
},
)
return
output_cookies = []
input_cookies = _get_all_cookies(request, cookie_jars)
Expand Down
27 changes: 27 additions & 0 deletions tests/test_api_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,33 @@ def test_automap_header_settings(settings, headers, meta, expected, warnings, ca
[],
[],
),
# Setting requestCookies to [] disables automatic mapping, but logs a
# a warning recommending to either use False to achieve the same or
# remove the parameter to let automated mapping work.
(
{
"ZYTE_API_EXPERIMENTAL_COOKIES_ENABLED": True,
},
REQUEST_INPUT_COOKIES_MINIMAL_DICT,
{},
{
"experimental": {
"requestCookies": [],
}
},
{
"httpResponseBody": True,
"httpResponseHeaders": True,
"experimental": {
"requestCookies": [],
"responseCookies": True,
},
},
[
"is overriding automatic request cookie mapping",
],
[],
),
# Cookies work for browser and automatic extraction requests as well.
(
{
Expand Down