Subject: 31.0.50; Make dynamic binding of url-max-redirections work
From: "Peder O. Klingenberg" <[email-masked]>
To: [email-masked]
Date: Wed, 06 Aug 2025 22:28:18 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Following on from bug#61916, there was one variable I missed that should
also have a faux-dynamic binding: url-max-redirections.

To demonstrate:

(setq url-debug t) ;; and follow the results in the *URL-DEBUG* buffer
(setq url-max-redirections 30) ;; the default

(let ((url-max-redirections 0))
  (url-retrieve "http://httpbin.org/redirect/5"
    #'(lambda (&rest _args)
        (message "done"))))

This will cause 5 redirections to be followed by url-http.el, because it
still sees url-max-redirections as 30.

With the attached patch it stops after the first redirection.

-- 
...Peder...

From 245b1935fdb9337b0e59932eefe6c62158eeff3d Mon Sep 17 00:00:00 2001
From: "Peder O. Klingenberg" <[email-masked]>
Date: Wed, 6 Aug 2025 21:55:38 +0200
Subject: [PATCH] Emulate dynamic binding of url-max-redirections

* lisp/url/url-http.el (url-http): Make url-max-redirections
buffer-local in request buffers, to make dynamic binding over
`url-retrieve` work as expected.
---
 lisp/url/url-http.el | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el
index a230a37e9ff..04fee189cfa 100644
--- a/lisp/url/url-http.el
+++ b/lisp/url/url-http.el
@@ -1372,7 +1372,8 @@ url-http
          (httpver url-http-version)
          (httpkeepalive url-http-attempt-keepalives)
          (user-agent url-user-agent)
-         (privacy-level url-privacy-level))
+         (privacy-level url-privacy-level)
+         (max-redirections url-max-redirections))
     (if (not connection)
 	;; Failed to open the connection for some reason
 	(progn
@@ -1418,6 +1419,7 @@ url-http
                        url-http-extensions-header
                        url-user-agent
                        url-privacy-level
+                       url-max-redirections
                        nsm-noninteractive))
 	  (set (make-local-variable var) nil))
 
@@ -1447,6 +1449,7 @@ url-http
               url-http-extensions-header url-extensions-header
               url-user-agent user-agent
               url-privacy-level privacy-level
+              url-max-redirections max-redirections
               nsm-noninteractive noninteractive-p)
 
 	(set-process-buffer connection buffer)
-- 
2.25.1