Skip to content

Commit 4e42e90

Browse files
authored
Merge pull request #1 from jonathan-3play/main
feat(--insecure) Allow insecure connections / no certificate validation
2 parents f483c0b + b0c22e6 commit 4e42e90

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Options:
99
-T, --timeout INTEGER Request timeout in seconds
1010
-a, --accept TEXT Accept header value
1111
-j, --json Report in JSON
12+
-k, --insecure Don't verify certificates
1213
-b, --body Show response body
1314
-L, --link-type TEXT Follow link header with type
1415
-R, --link-rel TEXT Follow link header with rel

htrace/__main__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import time
88
import urllib.parse
9+
import urllib3
910

1011
W = '\033[0m' # white (normal)
1112
R = '\033[31m' # red
@@ -15,7 +16,7 @@
1516
P = '\033[35m' # purple
1617

1718
#Global for access by event hooks
18-
session = requests.Session()
19+
session = requests.Session()
1920

2021
def printSummary(s):
2122
L = logging.getLogger("SUMMARY:")
@@ -69,13 +70,17 @@ def cbLinkFollow(response, *args, **kwargs):
6970
@click.option("-T", "--timeout", default=10, help="Request timeout in seconds")
7071
@click.option("-a", "--accept", default="*/*", help="Accept header value")
7172
@click.option("-j", "--json", "json_report", is_flag=True, help="Report in JSON")
73+
@click.option("-k", "--insecure", default=False, is_flag=True, help="Don't verify certificates")
7274
@click.option("-b", "--body", is_flag=True, help="Show response body")
7375
@click.option("-L", "--link-type", default=None, help="Follow link header with type")
7476
@click.option("-R", "--link-rel", default='alternate', help="Follow link header with rel")
7577
@click.option("-P", "--link-profile", default=None, help="Follow link header with profile")
76-
def main(url, timeout, accept, json_report, body, link_type, link_rel, link_profile):
78+
def main(url, timeout, accept, json_report, insecure, body, link_type, link_rel, link_profile):
79+
if insecure:
80+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
81+
7782
logging.basicConfig(
78-
level=logging.INFO,
83+
level=logging.INFO,
7984
format="%(asctime)s.%(msecs)03d:%(name)s %(message)s",
8085
datefmt='%Y-%m-%d %H:%M:%S')
8186
accept = htrace.ACCEPT_VALUES.get(accept, accept)
@@ -89,11 +94,11 @@ def main(url, timeout, accept, json_report, body, link_type, link_rel, link_prof
8994
}
9095
tstart = time.time()
9196
session._extra = {
92-
'link_type':link_type,
93-
'link_rel': link_rel,
97+
'link_type':link_type,
98+
'link_rel': link_rel,
9499
'link_profile': link_profile
95100
}
96-
response = session.get(url, timeout=timeout, headers=headers, hooks=hooks, allow_redirects=True)
101+
response = session.get(url, timeout=timeout, headers=headers, hooks=hooks, allow_redirects=True, verify=not insecure)
97102
tend = time.time()
98103
summary = htrace.responseSummary(response, tstart, tend)
99104
if json_report:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "htrace"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
description = "Tracing HTTP requests over redirects, link headers"
55
authors = ["datadavev <[email protected]>"]
66
license = "Apache 2.0"

0 commit comments

Comments
 (0)