From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Re: Avoid a redirect loop in url-http Date: Thu, 12 Apr 2007 11:48:51 -0400 Message-ID: <87fy757fvg.fsf@stupidchicken.com> References: <87hcrp0vzp.fsf@x3y2z1.net> <87tzvmrzs7.fsf@stupidchicken.com> <87slb5u2tt.fsf@x3y2z1.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1176392948 25622 80.91.229.12 (12 Apr 2007 15:49:08 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 12 Apr 2007 15:49:08 +0000 (UTC) Cc: emacs-devel@gnu.org To: Diane Murray Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Apr 12 17:49:05 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Hc1Xj-00069K-Nv for ged-emacs-devel@m.gmane.org; Thu, 12 Apr 2007 17:49:03 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Hc1bu-0003z6-5U for ged-emacs-devel@m.gmane.org; Thu, 12 Apr 2007 11:53:22 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Hc1bp-0003yp-Br for emacs-devel@gnu.org; Thu, 12 Apr 2007 11:53:17 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Hc1bo-0003yh-1I for emacs-devel@gnu.org; Thu, 12 Apr 2007 11:53:16 -0400 Original-Received: from south-station-annex.mit.edu ([18.72.1.2]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Hc1Xc-0006jp-99 for emacs-devel@gnu.org; Thu, 12 Apr 2007 11:48:56 -0400 Original-Received: from central-city-carrier-station.mit.edu (CENTRAL-CITY-CARRIER-STATION.MIT.EDU [18.7.7.72]) by south-station-annex.mit.edu (8.13.6/8.9.2) with ESMTP id l3CFms9D029407; Thu, 12 Apr 2007 11:48:55 -0400 (EDT) Original-Received: from outgoing-legacy.mit.edu (OUTGOING-LEGACY.MIT.EDU [18.7.22.104]) by central-city-carrier-station.mit.edu (8.13.6/8.9.2) with ESMTP id l3CFmpVf009466; Thu, 12 Apr 2007 11:48:52 -0400 (EDT) Original-Received: from localhost (SYDNEYPACIFIC-FIVE-SEVENTY-SIX.MIT.EDU [18.95.7.65]) ) by outgoing-legacy.mit.edu (8.13.6/8.12.4) with ESMTP id l3CFmph3004014; Thu, 12 Apr 2007 11:48:51 -0400 (EDT) Original-Received: from cyd by localhost with local (Exim 3.36 #1 (Debian)) id 1Hc1XX-0001Z6-00; Thu, 12 Apr 2007 11:48:51 -0400 In-Reply-To: <87slb5u2tt.fsf@x3y2z1.net> (Diane Murray's message of "Thu\, 12 Apr 2007 15\:42\:06 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.97 (gnu/linux) X-Scanned-By: MIMEDefang 2.42 X-Spam-Score: -2.599 X-detected-kernel: Solaris 9.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:69335 Archived-At: Diane Murray 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