From e9b6cf09df5021dff7be40fb5d004e0f86c92bf4 Mon Sep 17 00:00:00 2001 From: Nataliia Kovalchuk Date: Fri, 2 Feb 2024 08:57:32 +0100 Subject: [PATCH] fix: Update requests methods --- ckan_pkg_checker/utils/request_utils.py | 26 +++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/ckan_pkg_checker/utils/request_utils.py b/ckan_pkg_checker/utils/request_utils.py index 09ad290..df1618b 100644 --- a/ckan_pkg_checker/utils/request_utils.py +++ b/ckan_pkg_checker/utils/request_utils.py @@ -24,14 +24,24 @@ def check_url_status(test_url, http_method="HEAD"): "Chrome/55.0.2883.75 " "Safari/537.36" ) - req = session.request( - http_method, - test_url, - verify=False, - timeout=30, - headers={"User-Agent": user_agent}, - stream=True, # data is downloaded in smaller chunks - ) + if http_method == "HEAD": + req = requests.head( + test_url, + verify=False, # SSL certificate will not be verified + timeout=30, + headers={"User-Agent": user_agent}, + ) + elif http_method == "GET": + req = requests.get( + test_url, + verify=False, # SSL certificate will not be verified + timeout=30, + headers={ + "Range": "bytes=0-10", # Request the first 10 bytes + "User-Agent": user_agent, + }, + stream=True, # Data is downloaded in smaller chunks + ) req.raise_for_status() log.info("sent response %s" % req.status_code) except requests.exceptions.HTTPError as e: