66import json
77import time
88import urllib .parse
9+ import urllib3
910
1011W = '\033 [0m' # white (normal)
1112R = '\033 [31m' # red
1516P = '\033 [35m' # purple
1617
1718#Global for access by event hooks
18- session = requests .Session ()
19+ session = requests .Session ()
1920
2021def 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 :
0 commit comments