From e33e75245bc8b88e3d1dde7273177ca116c5020d Mon Sep 17 00:00:00 2001 From: Saul Pwanson Date: Wed, 28 Jun 2023 21:52:20 -0700 Subject: [PATCH] [http-] add options.http_ssl_verify to replace options.http_req_verify #1939 --- visidata/loaders/http.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/visidata/loaders/http.py b/visidata/loaders/http.py index b79b706ec..a8bbee740 100644 --- a/visidata/loaders/http.py +++ b/visidata/loaders/http.py @@ -9,6 +9,7 @@ vd.option('http_max_next', 0, 'max next.url pages to follow in http response') #848 vd.option('http_req_headers', {}, 'http headers to send to requests') +vd.option('http_ssl_verify', True, 'verify host and certificates for https') @VisiData.api @@ -25,16 +26,23 @@ def openurl_http(vd, path, filetype=None): import urllib.error import mimetypes - # fallback to mime-type + ctx = None + if not vd.options.http_ssl_verify: + import ssl + + ctx = ssl.create_default_context() + ctx.check_hostname = False + ctx.verify_mode = ssl.CERT_NONE + req = urllib.request.Request(path.given, **vd.options.getall('http_req_')) - response = urllib.request.urlopen(req) + response = urllib.request.urlopen(req, context=ctx) contenttype = response.getheader('content-type') subtype = contenttype.split(';')[0].split('/')[-1] - filetype = filetype or vd.guessFiletype(path, funcprefix='guessurl_').get('filetype') - filetype = filetype or content_filetypes.get(subtype, subtype) - filetype = filetype or vd.guessFiletype(path).get('filetype') + filetype = filetype or vd.guessFiletype(path, funcprefix='guessurl_').get('filetype') # try guessing by url + filetype = filetype or content_filetypes.get(subtype, subtype) # try mime-type + filetype = filetype or vd.guessFiletype(path).get('filetype') # try guessing by contents # Automatically paginate if a 'next' URL is given def _iter_lines(path=path, response=response, max_next=vd.options.http_max_next):