all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Chong Yidong <cyd@stupidchicken.com>
To: Diane Murray <disumu@x3y2z1.net>
Cc: emacs-devel@gnu.org
Subject: Re: Avoid a redirect loop in url-http
Date: Thu, 12 Apr 2007 11:48:51 -0400	[thread overview]
Message-ID: <87fy757fvg.fsf@stupidchicken.com> (raw)
In-Reply-To: <87slb5u2tt.fsf@x3y2z1.net> (Diane Murray's message of "Thu\, 12 Apr 2007 15\:42\:06 +0200")

Diane Murray <disumu@x3y2z1.net> writes:

> There are sites that for some reason or another keep returning
> redirect responses.  Some redirect to the same host and file path
> but with slightly different query arguments, possibly because the
> page expects a cookie to be set and url-cookie doesn't allow it.
> Other mischievous sites might do something similar just to try and
> cause problems.  Since these are all distinct URLs, they won't be
> equal, which is why I suggested checking how many times the request
> has been redirected.

I see.

How about this patch?

*** emacs/lisp/url/url-vars.el.~1.16.~	2007-01-20 22:24:41.000000000 -0500
--- emacs/lisp/url/url-vars.el	2007-04-12 11:32:34.000000000 -0400
***************
*** 320,325 ****
--- 320,331 ----
    "\\`\\([-a-zA-Z0-9+.]+:\\)"
    "A regular expression that will match an absolute URL.")
  
+ (defcustom url-max-redirections 30
+   "*The maximum number of redirection requests to honor in a HTTP connection.
+ A negative number means to honor an unlimited number of redirection requests."
+   :type 'integer
+   :group 'url)
+ 
  (defcustom url-confirmation-func 'y-or-n-p
    "*What function to use for asking yes or no functions.
  Possible values are `yes-or-no-p' or `y-or-n-p', or any function that
*** 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 11:44:48.000000000 -0400
***************
*** 556,561 ****
--- 556,575 ----
             (let ((url-request-method url-http-method)
  		 (url-request-data url-http-data)
  		 (url-request-extra-headers url-http-extra-headers))
+ 	     ;; Check existing number of redirects
+ 	     (if (or (< url-max-redirections 0)
+ 		     (and (> url-max-redirections 0)
+ 			  (let ((events (car url-callback-arguments))
+ 				(old-redirects 0))
+ 			    (while events
+ 			      (if (eq (car events) :redirect)
+ 				  (setq old-redirects (1+ old-redirects)))
+ 			      (and (setq events (cdr events))
+ 				   (setq events (cdr events))))
+ 			    (< old-redirects url-max-redirections))))
+ 		 ;; url-max-redirections hasn't been reached, so go
+ 		 ;; ahead and redirect.
+ 		 (progn
  	     ;; 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
--- 584,598 ----
  		   (url-retrieve-internal
  		    redirect-uri url-callback-function
  		    url-callback-arguments))
! 	      (url-mark-buffer-as-dead (current-buffer)))
! 	       ;; We hit url-max-redirections, so issue an error and
! 	       ;; stop redirecting.
! 	       (setf (car url-callback-arguments)
! 		     (nconc (list :error (list 'error
! 					       'http
! 					       url-http-response-status))
! 			    (car url-callback-arguments)))
! 	       (setq success t))))))
        (4				; Client error
         ;; 400 Bad Request
         ;; 401 Unauthorized

  reply	other threads:[~2007-04-12 15:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-10  3:05 Avoid a redirect loop in url-http Diane Murray
2007-04-12  4:18 ` Chong Yidong
2007-04-12 10:25   ` Kim F. Storm
2007-04-12 13:42   ` Diane Murray
2007-04-12 15:48     ` Chong Yidong [this message]
2007-04-13 12:36       ` Diane Murray
2007-04-13 15:00         ` Chong Yidong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fy757fvg.fsf@stupidchicken.com \
    --to=cyd@stupidchicken.com \
    --cc=disumu@x3y2z1.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.