From 0c219f7c863f9cf2a1cb34e3513cc37d2b072a16 Mon Sep 17 00:00:00 2001
From: Alexandre Dulaunoy
Date: Thu, 13 Jul 2023 08:52:32 +0200
Subject: [PATCH] chg: [hhhash] add options including setting the HTTP method
Fix #1
---
hhhash/create.py | 17 +++++++++++++++--
pyproject.toml | 2 +-
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/hhhash/create.py b/hhhash/create.py
index 3e06899..787f649 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 "
]