Coverage for pyguymer3/download_header.py: 10%
10 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
1#!/usr/bin/env python3
3# Define function ...
4def download_header(
5 sess,
6 url,
7 /,
8 *,
9 cookies = None,
10 headers = None,
11 timeout = 10.0,
12 verify = True,
13):
14 """HEAD a URL and return the headers
16 This function performs a HTTP HEAD operation on a URL and returns the
17 headers.
19 Parameters
20 ----------
21 sess : requests.sessions.Session
22 the :mod:`requests` session to use
23 url : str
24 the URL
25 cookies : dict, optional
26 the cookie jar
27 headers : dict, optional
28 extra headers to send
29 timeout : float, optional
30 the timeout of the HEAD request
31 verify : bool, optional
32 verify the server's certificates
34 Returns
35 -------
36 resp : bool, bytes
37 `False` if unsuccessful or a `dict` if successful
39 Notes
40 -----
41 Copyright 2017 Thomas Guymer [1]_
43 References
44 ----------
45 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3
46 """
48 # Import sub-functions ...
49 from .download import download
51 # Populate default values ...
52 if cookies is None:
53 cookies = {}
54 if headers is None:
55 headers = {}
57 # **************************************************************************
59 # Try to get the headers ...
60 resp = download(
61 sess,
62 "head",
63 url,
64 cookies = cookies,
65 headers = headers,
66 timeout = timeout,
67 verify = verify,
68 )
70 # Check response ...
71 if resp is False:
72 return False
74 # Return answer ...
75 return resp.headers