GNU bug report logs - #61916
30.0.50; url.el; Can not change User-Agent temporarily when url-retrieve

Previous Next

Package: emacs;

Reported by: xhcoding <xhcoding <at> foxmail.com>

Date: Thu, 2 Mar 2023 14:46:02 UTC

Severity: normal

Tags: patch

Found in version 30.0.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Full log


View this message in rfc822 format

From: "Peder O. Klingenberg" <peder <at> klingenberg.no>
To: xhcoding <xhcoding <at> foxmail.com>
Cc: 61916 <at> debbugs.gnu.org
Subject: bug#61916: 30.0.50; url.el; Can not change User-Agent temporarily when url-retrieve
Date: Fri, 18 Jul 2025 14:57:58 +0200
tags 61916 + patch
quit

On Thu, 2023-03-02 21:37:13 +0800, xhcoding wrote:

> The following code cannot be used to temporarily change User-Agent
>
> (require 'url)
> (setq url-debug t)
> (let ((url-user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.57"))
>   (url-retrieve "https://httpbin.org/get?a=b" (lambda (_))))

Some, but not all, variables used to construct a request by url-http.el
have their dynamic values preserved in the buffer used for the async
communication. url-user-agent was not among the so blessed.  For the
unlucky variables, the behaviour is extra confusing because connections
are sometimes re-used (due to http keep-alive), in which case the
dynamic bindings _do_ work as expected.

This same issue hit me as I was working on improving restclient.el,
where some of the bug reports probably originate from this confusing
behaviour of url-http.el.

Attached is a patch that extends the set of dynamic-values-at-call-time
-> buffer-local-available-at-request-time variables.  With this, your
test case works as expected, as do my experiments in restclient.

Hopefully this will be picked up by someone with commit privileges.

-- 
...Peder...




This bug report was last modified 15 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.