diff mbox series

[v3,1/5] fetch2/wget: enable classes derived from Wget to set custom http headers

Message ID 20250307120055.1816436-2-l.goehrs@pengutronix.de
State New
Headers show
Series fetch2/github_release_artifact: fetcher for (private) release artifacts | expand

Commit Message

Leonard Göhrs March 7, 2025, noon UTC
This allows derived fetchers to e.g. set a `Authorization: Bearer ...`
header for token based authentication, or `Accept:` headers to restrict
which file type the fetcher expects.

Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
---
 lib/bb/fetch2/wget.py | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/lib/bb/fetch2/wget.py b/lib/bb/fetch2/wget.py
index 6cb728ab4..e13730b48 100644
--- a/lib/bb/fetch2/wget.py
+++ b/lib/bb/fetch2/wget.py
@@ -121,6 +121,9 @@  class Wget(FetchMethod):
                 # Authorization header.
                 fetchcmd += " --user=%s --password=%s" % (ud.user, ud.pswd)
 
+        for key, value in getattr(ud, "http_headers", {}).items():
+            fetchcmd += " --header='%s: %s'" % (key, value)
+
         uri = ud.url.split(";")[0]
         if os.path.exists(ud.localpath):
             # file exists, but we didnt complete it.. trying again..
@@ -394,6 +397,9 @@  class Wget(FetchMethod):
                 if ud.user and ud.pswd:
                     add_basic_auth(ud.user + ':' + ud.pswd, r)
 
+                for key, value in getattr(ud, "http_headers", {}).items():
+                    r.add_header(key, value)
+
                 try:
                     import netrc
                     auth_data = netrc.netrc().authenticators(urllib.parse.urlparse(uri).hostname)