Skip to contentSkip to conversation

wget.py: always use the custom user agent

PATCH Superseded [email protected] 2 participants 3 messages Feb 9, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wget.py: always use the custom user agent

From: Thomas Perrot <[email protected]>

Add the "--user-agent" paramater in the wget base command to perform all wget commands with this parameter, because a few HTTP servers block requests with the default wget user agent.

For example, "hg.openjdk.org" never send a response to requests have been sent with wget:
wget https://hg.openjdk.org/jdk8u/jdk8u/archive/jdk8u272-ga.tar.bz2
https://hg.openjdk.org/jdk8u/jdk8u/archive/jdk8u272-ga.tar.bz2
Resolving hg.openjdk.org (hg.openjdk.org)... 23.54.129.73 Connecting to hg.openjdk.org (hg.openjdk.org)|23.54.129.73|:443... connected. HTTP request sent, awaiting response...

---
 lib/bb/fetch2/wget.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/bb/fetch2/wget.py +4 -3
index dc025800e659..e7c4cdd396b3 100644
@@ -87,7 +87,8 @@ class Wget(FetchMethod):
         if not ud.localfile:
             ud.localfile = d.expand(urllib.parse.unquote(ud.host + ud.path).replace("/", "."))
 
-        self.basecmd = d.getVar("FETCHCMD_wget") or "/usr/bin/env wget -t 2 -T 30 --passive-ftp"
+        self.basecmd = d.getVar("FETCHCMD_wget") \
+            or "/usr/bin/env wget -t 2 -T 30 --passive-ftp --user-agent='%s'" % (self.user_agent)
 
         if not self.check_certs(d):
             self.basecmd += " --no-check-certificate"
@@ -454,7 +455,7 @@ class Wget(FetchMethod):
         f = tempfile.NamedTemporaryFile()
         with tempfile.TemporaryDirectory(prefix="wget-index-") as workdir, tempfile.NamedTemporaryFile(dir=workdir, prefix="wget-listing-") as f:
             fetchcmd = self.basecmd
-            fetchcmd += " -O " + f.name + " --user-agent='" + self.user_agent + "' '" + uri + "'"
+            fetchcmd += " -O '" + uri + "'"
             try:
                 self._runwget(ud, d, fetchcmd, True, workdir=workdir)
                 fetchresult = f.read()
@@ -492,7 +493,7 @@ class Wget(FetchMethod):
                     valid = 1
                 elif self._vercmp(version, newver) < 0:
                     version = newver
-                
+
         pupver = re.sub('_', '.', version[1])
 
         bb.debug(3, "*** %s -> UpstreamVersion = %s (CurrentVersion = %s)" %
Signature · 1 line
2.43.0
#1 lore raw

Thomas Perrot via lists.openembedded.org <thomas.perrot= [email protected]> escreveu (sexta, 9/02/2024 à(s) 15:25):

Quoted 41 lines

From: Thomas Perrot <[email protected]>

Add the "--user-agent" paramater in the wget base command to perform all wget commands with this parameter, because a few HTTP servers block requests with the default wget user agent.

For example, "hg.openjdk.org" never send a response to requests have been sent with wget:
wget https://hg.openjdk.org/jdk8u/jdk8u/archive/jdk8u272-ga.tar.bz2
https://hg.openjdk.org/jdk8u/jdk8u/archive/jdk8u272-ga.tar.bz2
Resolving hg.openjdk.org (hg.openjdk.org)... 23.54.129.73 Connecting to hg.openjdk.org (hg.openjdk.org)|23.54.129.73|:443... connected.
HTTP request sent, awaiting response...

---
 lib/bb/fetch2/wget.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/bb/fetch2/wget.py +0 -1
index dc025800e659..e7c4cdd396b3 100644
@@ -87,7 +87,8 @@ class Wget(FetchMethod):
         if not ud.localfile:
             ud.localfile = d.expand(urllib.parse.unquote(ud.host +
 ud.path).replace("/", "."))
 
-        self.basecmd = d.getVar("FETCHCMD_wget") or "/usr/bin/env wget -t

2 -T 30 --passive-ftp"

lib/bb/fetch2/wget.py +2 -1
+        self.basecmd = d.getVar("FETCHCMD_wget") \
+            or "/usr/bin/env wget -t 2 -T 30 --passive-ftp
--user-agent='%s'" % (self.user_agent)
 
         if not self.check_certs(d):
             self.basecmd += " --no-check-certificate"
@@ -454,7 +455,7 @@ class Wget(FetchMethod):
         f = tempfile.NamedTemporaryFile()
         with tempfile.TemporaryDirectory(prefix="wget-index-") as
 workdir, tempfile.NamedTemporaryFile(dir=workdir, prefix="wget-listing-")
Quoted 6 lines

as f:
fetchcmd = self.basecmd
- fetchcmd += " -O " + f.name + " --user-agent='" +
self.user_agent + "' '" + uri + "'"
+ fetchcmd += " -O '" + uri + "'"

Looks like the file name was removed unintentional.

Jose

Quoted 28 lines

try:
self._runwget(ud, d, fetchcmd, True, workdir=workdir) fetchresult = f.read()

lib/bb/fetch2/wget.py +1 -1
@@ -492,7 +493,7 @@ class Wget(FetchMethod):
                     valid = 1
                 elif self._vercmp(version, newver) < 0:
                     version = newver
-
+
         pupver = re.sub('_', '.', version[1])
 
         bb.debug(3, "*** %s -> UpstreamVersion = %s (CurrentVersion =

%s)" %
--
2.43.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#15851):
https://lists.openembedded.org/g/bitbake-devel/message/15851
Mute This Topic: https://lists.openembedded.org/mt/104260370/5052612
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 3 lines
Best regards,

José Quaresma
#2 lore raw

Hello Jose,

Quoted 40 lines · Jose Quaresma

Thomas Perrot via lists.openembedded.org <[email protected]> escreveu (sexta, 9/02/2024 à(s) 15:25):

Quoted 35 lines

From: Thomas Perrot <[email protected]>

Add the "--user-agent" paramater in the wget base command to perform all wget commands with this parameter, because a few HTTP servers block requests with the default wget user agent.

For example, "hg.openjdk.org" never send a response to requests have been sent with wget:
wget https://hg.openjdk.org/jdk8u/jdk8u/archive/jdk8u272-ga.tar.bz2
https://hg.openjdk.org/jdk8u/jdk8u/archive/jdk8u272-ga.tar.bz2
Resolving hg.openjdk.org (hg.openjdk.org)... 23.54.129.73 Connecting to hg.openjdk.org (hg.openjdk.org)|23.54.129.73|:443... connected.
HTTP request sent, awaiting response...

---
 lib/bb/fetch2/wget.py | 7 ++++---

 1 file changed, 4 insertions(+), 3 deletions(-)
lib/bb/fetch2/wget.py +0 -0
index dc025800e659..e7c4cdd396b3 100644
@@ -87,7 +87,8 @@ class Wget(FetchMethod):

         if not ud.localfile:
             ud.localfile = d.expand(urllib.parse.unquote(ud.host + ud.path).replace("/", "."))

-        self.basecmd = d.getVar("FETCHCMD_wget") or "/usr/bin/env wget -t 2 -T 30 --passive-ftp"
+        self.basecmd = d.getVar("FETCHCMD_wget") \
+            or "/usr/bin/env wget -t 2 -T 30 --passive-ftp --user- agent='%s'" % (self.user_agent)

Quoted 15 lines
Quoted 4 lines

         if not self.check_certs(d):
             self.basecmd += " --no-check-certificate"

lib/bb/fetch2/wget.py +0 -0
@@ -454,7 +455,7 @@ class Wget(FetchMethod):
          f = tempfile.NamedTemporaryFile()
Quoted 8 lines

         with tempfile.TemporaryDirectory(prefix="wget-index-") as workdir, tempfile.NamedTemporaryFile(dir=workdir, prefix="wget- listing-") as f:
             fetchcmd = self.basecmd
-            fetchcmd += " -O " + f.name + " --user-agent='" + self.user_agent + "' '" + uri + "'"
+            fetchcmd += " -O '" + uri + "'"

Looks like the file name was removed unintentional.

Really sorry for this error, I'm sending a v2.

Kind regards,
Thomas Perrot

Quoted 30 lines

Jose

Quoted 27 lines

             try:
                 self._runwget(ud, d, fetchcmd, True, workdir=workdir)
                 fetchresult = f.read()

lib/bb/fetch2/wget.py +0 -0
@@ -492,7 +493,7 @@ class Wget(FetchMethod):

                     valid = 1
                 elif self._vercmp(version, newver) < 0:
                     version = newver
-
+
         pupver = re.sub('_', '.', version[1])

         bb.debug(3, "*** %s -> UpstreamVersion = %s (CurrentVersion = %s)" %

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#15853):
https://lists.openembedded.org/g/bitbake-devel/message/15853
Mute This Topic:
https://lists.openembedded.org/mt/104260370/5443093
Group Owner: [email protected] Unsubscribe:
https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]
]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 3 lines
Thomas Perrot, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com