diff --git a/scrapy_zyte_api/_params.py b/scrapy_zyte_api/_params.py index 2d460316..0a63e087 100644 --- a/scrapy_zyte_api/_params.py +++ b/scrapy_zyte_api/_params.py @@ -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) diff --git a/tests/test_api_requests.py b/tests/test_api_requests.py index 91998835..4f805a3a 100644 --- a/tests/test_api_requests.py +++ b/tests/test_api_requests.py @@ -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. ( {