commit:     40553e8196363fe6f49a5a7a25a20243aec6341a
Author:     Florian Schmaus <flow <AT> gentoo <DOT> org>
AuthorDate: Fri Sep 12 12:29:32 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Sep 12 21:17:22 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=40553e81

Introduce PORTAGE_SHOW_HTTP_TRACE functionality

The HTTP trace comes in handy to debug issues with e.g., a binhost, or
to analyse and optimize portage's HTTP request handling.

[sam: add Bug tag.]

Bug: https://bugs.gentoo.org/962557
Signed-off-by: Florian Schmaus <flow <AT> gentoo.org>
Part-of: https://github.com/gentoo/portage/pull/1460
Closes: https://github.com/gentoo/portage/pull/1460
Signed-off-by: Sam James <sam <AT> gentoo.org>

 NEWS                | 3 +++
 lib/_emerge/main.py | 6 ++++++
 man/emerge.1        | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/NEWS b/NEWS
index b7e667c517..a7c131bf66 100644
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,9 @@ Features:
 * Portage will now show statistics about its internal LRU caches if the
   PORTAGE_SHOW_LRU_CACHE_INFO environment variable is set.
 
+* Portage will show a HTTP trace if the PORTAGE_SHOW_HTTP_TRACE environment
+  variable is set.
+
 * Introduce PORTAGE_LOG_FILE_SEP, allowing to configure the separator between
   the components of the log files produced by portage.
 

diff --git a/lib/_emerge/main.py b/lib/_emerge/main.py
index 44e05c3dfd..ababcf1736 100644
--- a/lib/_emerge/main.py
+++ b/lib/_emerge/main.py
@@ -1186,6 +1186,12 @@ def emerge_main(args: Optional[list[str]] = None):
     # EMERGE_DEFAULT_OPTS has been parsed).
     portage.output.havecolor = 0
 
+    if os.environ.get("PORTAGE_SHOW_HTTP_TRACE"):
+        import http.client
+
+        http.client.HTTPConnection.debuglevel = 1
+        http.client.HTTPSConnection.debuglevel = 1
+
     # This first pass is just for options that need to be known as early as
     # possible, such as --config-root.  They will be parsed again later,
     # together with EMERGE_DEFAULT_OPTS (which may vary depending on the

diff --git a/man/emerge.1 b/man/emerge.1
index 42fc53f95b..1dd826cde7 100644
--- a/man/emerge.1
+++ b/man/emerge.1
@@ -1451,6 +1451,9 @@ prior notice.
 .BR PORTAGE_SHOW_LRU_CACHE_INFO
 If this environment variable is set, then Portage will display
 statistics about its internal LRU caches.
+.BR PORTAGE_SHOW_HTTP_TRACE
+If this environment variable is set, then Portage will show
+a trace of all HTTP request.
 .SH "REPORTING BUGS"
 Please report any bugs you encounter through our website:
 .LP

Reply via email to