diff --git a/hhhash/create.py b/hhhash/create.py index faf5af8..3b1146d 100644 --- a/hhhash/create.py +++ b/hhhash/create.py @@ -2,10 +2,23 @@ import requests import hashlib -def buildhash(url=None, debug=False): +def buildhash(url=None, debug=False, method='GET', timeout=5): + """Build a HHHash from an HTTP request to specific url. + + Keyword arguments: + url -- the url to build the HHHash from the response headers (default None) + debug -- output the headers returned before hashing (default False) + method -- HTTP method to use (GET or HEAD) (default GET) + timeout -- default timeout for the connect/read timeout of request (default 2) + """ if url is None: return False - r = requests.get(url) + if method == 'GET': + r = requests.get(url, timeout=timeout) + elif method == 'HEAD': + r = requests.head(url, timeout=timeout) + else: + return False hhhash = "" for header in r.headers.keys(): hhhash = f"{hhhash}:{header}" diff --git a/pyproject.toml b/pyproject.toml index 8ed2283..8856b2b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ [tool.poetry] name = "HHHash" -version = "0.1" +version = "0.2" authors = [ "Alexandre Dulaunoy " ]