From e6ae18ab0dabe9ee35b57d3534bc0e25d32ee7b8 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 23 Sep 2024 15:32:23 +0300 Subject: [PATCH] Enhanced internet connection checks by falling back to HTTPS protocol when HTTP (port 80) fails // Resolve #4980 --- HISTORY.rst | 1 + platformio/http.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index e98d3110..23121849 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -22,6 +22,7 @@ test-driven methodologies, and modern toolchains for unrivaled success. ~~~~~~~~~~~~~~~~~~~ * Introduced the `PLATFORMIO_SYSTEM_TYPE `__ environment variable, enabling manual override of the detected system type for greater flexibility and control in custom build environments +* Enhanced internet connection checks by falling back to HTTPS protocol when HTTP (port 80) fails (`issue #4980 `_) * Upgraded the build engine to the latest version of SCons (4.8.1) to improve build performance, reliability, and compatibility with other tools and systems (`release notes `__) * Upgraded the `Doctest `__ testing framework to version 2.4.11, the `GoogleTest `__ to version 1.15.2, and the `Unity `__ to version 2.6.0, incorporating the latest features and improvements for enhanced testing capabilities * Corrected an issue where the incorrect public class was imported for the ``DoctestTestRunner`` (`issue #4949 `_) diff --git a/platformio/http.py b/platformio/http.py index d82e4703..3c77ff32 100644 --- a/platformio/http.py +++ b/platformio/http.py @@ -190,10 +190,11 @@ class HTTPClient: @util.memoized(expire="10s") def _internet_on(): timeout = 2 + use_proxy = is_proxy_set() socket.setdefaulttimeout(timeout) for host in __check_internet_hosts__: try: - if is_proxy_set(): + if use_proxy: requests.get("http://%s" % host, allow_redirects=False, timeout=timeout) return True # try to resolve `host` for both AF_INET and AF_INET6, and then try to connect @@ -203,6 +204,15 @@ def _internet_on(): return True except: # pylint: disable=bare-except pass + + # falling back to HTTPs, issue #4980 + for host in __check_internet_hosts__: + try: + requests.get("https://%s" % host, allow_redirects=False, timeout=timeout) + except requests.exceptions.RequestException: + pass + return True + return False