emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Avoid a redirect loop in url-http


From: Chong Yidong
Subject: Re: Avoid a redirect loop in url-http
Date: Thu, 12 Apr 2007 00:18:32 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.97 (gnu/linux)

Diane Murray <address@hidden> writes:

> On occasion url-http gets stuck in an endless redirect loop.  This can
> be fixed by simply checking if the number of redirected URLs in
> `url-callback-arguments' hasn't gone over a certain number (which
> could be a customizable variable).  If it has been redirected too many
> times, rather than call `url-retrieve-internal' again,
> `url-http-parse-headers' should just let the callback function get
> activated - after adding a redirect error to `url-callback-arguments',
> so that the callback knows that the maximum number of redirects was
> reached.

Thanks.

How about this patch?  It doesn't implement a defcustom as you
suggested; it simply searches for a redirect loop.  It also simply
signals an error if a loop is found.

(The indentation of existing code is left unchanged to make the patch
easier to read.)

*** emacs/lisp/url/url-http.el.~1.52.~  2007-04-01 11:32:35.000000000 -0400
--- emacs/lisp/url/url-http.el  2007-04-12 00:17:40.000000000 -0400
***************
*** 555,561 ****
                     (url-expand-file-name redirect-uri url-http-target-url)))
             (let ((url-request-method url-http-method)
                 (url-request-data url-http-data)
!                (url-request-extra-headers url-http-extra-headers))
             ;; Remember that the request was redirected.
             (setf (car url-callback-arguments)
                   (nconc (list :redirect redirect-uri)
--- 555,571 ----
                     (url-expand-file-name redirect-uri url-http-target-url)))
             (let ((url-request-method url-http-method)
                 (url-request-data url-http-data)
!                (url-request-extra-headers url-http-extra-headers)
!                (events (car url-callback-arguments)))
!            ;; Check for redirect loops
!            (while events
!              (if (eq (car events) :redirect)
!                  (and (setq events (cdr events))
!                       (if (eq (car events) redirect-uri)
!                           (error "HTTP redirect loop detected")
!                         (setq events (cdr events))))
!                (and (setq events (cdr events))
!                     (setq events (cdr events)))))
             ;; Remember that the request was redirected.
             (setf (car url-callback-arguments)
                   (nconc (list :redirect redirect-uri)
***************
*** 570,576 ****
                   (url-retrieve-internal
                    redirect-uri url-callback-function
                    url-callback-arguments))
!             (url-mark-buffer-as-dead (current-buffer))))))
        (4                              ; Client error
         ;; 400 Bad Request
         ;; 401 Unauthorized
--- 580,586 ----
                   (url-retrieve-internal
                    redirect-uri url-callback-function
                    url-callback-arguments))
!             (url-mark-buffer-as-dead (current-buffer)))))))
        (4                              ; Client error
         ;; 400 Bad Request
         ;; 401 Unauthorized




reply via email to

[Prev in Thread] Current Thread [Next in Thread]