Subject: Re: bug#61916: 30.0.50; url.el; Can not change User-Agent temporarily when url-retrieve

From: "Peder O. Klingenberg" <[email-masked]>
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...