Skip to content

Commit

Permalink
Warn about requestCookies=[]
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallaecio committed Jul 24, 2023
1 parent 23762b6 commit 9782552
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
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

0 comments on commit 9782552

Please sign in to comment.