From: Michael Tremer Date: Thu, 1 Dec 2016 18:52:37 +0000 (+0100) Subject: http: Automatically configure client X-Git-Tag: 0.9.28~1285^2~1440 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b83a54590c497dec3cbacc3ef98e3fc25a030d5c;p=pakfire.git http: Automatically configure client This patch makes the HTTP client read some basic settings from the configuration file. Signed-off-by: Michael Tremer --- diff --git a/contrib/config/general.conf b/contrib/config/general.conf index 864cfb3db..6f2b8625e 100644 --- a/contrib/config/general.conf +++ b/contrib/config/general.conf @@ -6,21 +6,13 @@ #debug = false [downloader] -# Pakfire can use a HTTP proxy for all downloads. -# Authentication can be used like this: -# http://foo:bar@192.168.180.1:800 +# Pakfire can use a proxy for HTTP, HTTPS and FTP # If no proxy setting is configured, Pakfire will # use the environment settings. -#http_proxy = http://192.168.180.1:800 +#proxy = http://192.168.180.1:800 -# You can throttle the download bandwidth with this -# parameter. Unit: bytes per second. -#bandwidth_throttle = 10240 - -# Offline mode. -# You may disable any kind of download action. -# Howevery, pakfire won't be fully functionable. -#offline = False +# Verify SSL certificates? +#verify = true [signatures] # Sets the mode of the signature verification. diff --git a/src/pakfire/http.py b/src/pakfire/http.py index 3b51d29b2..420ef33b5 100644 --- a/src/pakfire/http.py +++ b/src/pakfire/http.py @@ -29,6 +29,7 @@ import urllib.request from .ui import progressbar +from .config import config from .constants import * from . import errors @@ -49,13 +50,24 @@ class Client(object): # Create an SSL context to HTTPS connections self.ssl_context = ssl.create_default_context() + # Configure upstream proxies + proxy = config.get("downloader", "proxy") + if proxy: + for protocol in ("http", "https", "ftp"): + self.set_proxy(protocol, proxy) + + # Should we verify SSL certificates? + verify = config.get_bool("downloader", "verify", True) + if not verify: + self.disable_certificate_verification() + def set_proxy(self, protocol, host): """ Sets a proxy that will be used to send this request """ self.proxies[protocol] = host - def disable_certificate_validation(self): + def disable_certificate_verification(self): # Disable checking hostname self.ssl_context.check_hostname = False