tools.linux.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Vernet <void@manifault.com>
To: konstantin@linuxfoundation.org
Cc: users@linux.kernel.org, tools@linux.kernel.org, void@manifault.com
Subject: [PATCH] mbox: Add support for proxied https connections
Date: Tue, 18 Jan 2022 09:41:45 -0800	[thread overview]
Message-ID: <20220118174144.2445150-1-void@manifault.com> (raw)

The mbox subsystem uses the python requests library to fetch a thread from
lore.kernel.org, by its message ID. This is extremely convenient, but
unfortunately doesn't work for users who must redirect their http(s)
traffic through a proxy to access the internet.

This diff therefore adds support for querying 'http.proxy' from their git
config, and when set, passing that as a proxy entry to the underlying
session requests object.

Signed-off-by: David Vernet <void@manifault.com>
---
 b4/__init__.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/b4/__init__.py b/b4/__init__.py
index 11c287e..0526a19 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -138,6 +138,8 @@ DEFAULT_CONFIG = {
 MAIN_CONFIG = None
 # This is git-config user.*
 USER_CONFIG = None
+# This is git-config http.*
+HTTP_CONFIG = None
 
 # Used for storing our requests session
 REQSESSION = None
@@ -2101,12 +2103,21 @@ def get_user_config():
             USER_CONFIG['name'] = udata.pw_gecos
     return USER_CONFIG
 
+def get_http_config():
+    global HTTP_CONFIG
+    if HTTP_CONFIG is None:
+        HTTP_CONFIG = get_config_from_git(r'http\..*')
+    return HTTP_CONFIG
 
 def get_requests_session():
     global REQSESSION
     if REQSESSION is None:
         REQSESSION = requests.session()
         REQSESSION.headers.update({'User-Agent': 'b4/%s' % __VERSION__})
+        http_config = get_http_config()
+        if 'proxy' in http_config:
+            REQSESSION.proxies.update({'https': http_config['proxy']})
+
     return REQSESSION
 
 
-- 
2.30.2


             reply	other threads:[~2022-01-18 17:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-18 17:41 David Vernet [this message]
2022-01-18 18:00 ` [PATCH] mbox: Add support for proxied https connections Konstantin Ryabitsev
2022-01-18 18:14   ` David Vernet
2022-01-18 18:28     ` Konstantin Ryabitsev
2022-01-18 19:42       ` David Vernet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220118174144.2445150-1-void@manifault.com \
    --to=void@manifault.com \
    --cc=konstantin@linuxfoundation.org \
    --cc=tools@linux.kernel.org \
    --cc=users@linux.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).