aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2007-04-13 14:58:56 +0000
committerChong Yidong2007-04-13 14:58:56 +0000
commit58aba8143c1e9c1807d23ca5f6bb243c5d84fe24 (patch)
treeaed4b4992a48f9aeecca6a99f5b48004ea82d46f
parent2faae86bd7a2bb27b3bb810ff1c6eb4c5b3181b8 (diff)
downloademacs-58aba8143c1e9c1807d23ca5f6bb243c5d84fe24.tar.gz
emacs-58aba8143c1e9c1807d23ca5f6bb243c5d84fe24.zip
(url-http-parse-headers): Stop after a set number of redirections.
Suggested by Diane Murray.
-rw-r--r--lisp/url/url-http.el52
1 files changed, 37 insertions, 15 deletions
diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el
index 10a6f2e7278..d9ac81838d4 100644
--- a/lisp/url/url-http.el
+++ b/lisp/url/url-http.el
@@ -556,21 +556,43 @@ should be shown to the user."
556 (let ((url-request-method url-http-method) 556 (let ((url-request-method url-http-method)
557 (url-request-data url-http-data) 557 (url-request-data url-http-data)
558 (url-request-extra-headers url-http-extra-headers)) 558 (url-request-extra-headers url-http-extra-headers))
559 ;; Remember that the request was redirected. 559 ;; Check existing number of redirects
560 (setf (car url-callback-arguments) 560 (if (or (< url-max-redirections 0)
561 (nconc (list :redirect redirect-uri) 561 (and (> url-max-redirections 0)
562 (car url-callback-arguments))) 562 (let ((events (car url-callback-arguments))
563 ;; Put in the current buffer a forwarding pointer to the new 563 (old-redirects 0))
564 ;; destination buffer. 564 (while events
565 ;; FIXME: This is a hack to fix url-retrieve-synchronously 565 (if (eq (car events) :redirect)
566 ;; without changing the API. Instead url-retrieve should 566 (setq old-redirects (1+ old-redirects)))
567 ;; either simply not return the "destination" buffer, or it 567 (and (setq events (cdr events))
568 ;; should take an optional `dest-buf' argument. 568 (setq events (cdr events))))
569 (set (make-local-variable 'url-redirect-buffer) 569 (< old-redirects url-max-redirections))))
570 (url-retrieve-internal 570 ;; url-max-redirections hasn't been reached, so go
571 redirect-uri url-callback-function 571 ;; ahead and redirect.
572 url-callback-arguments)) 572 (progn
573 (url-mark-buffer-as-dead (current-buffer)))))) 573 ;; Remember that the request was redirected.
574 (setf (car url-callback-arguments)
575 (nconc (list :redirect redirect-uri)
576 (car url-callback-arguments)))
577 ;; Put in the current buffer a forwarding pointer to the new
578 ;; destination buffer.
579 ;; FIXME: This is a hack to fix url-retrieve-synchronously
580 ;; without changing the API. Instead url-retrieve should
581 ;; either simply not return the "destination" buffer, or it
582 ;; should take an optional `dest-buf' argument.
583 (set (make-local-variable 'url-redirect-buffer)
584 (url-retrieve-internal
585 redirect-uri url-callback-function
586 url-callback-arguments))
587 (url-mark-buffer-as-dead (current-buffer)))
588 ;; We hit url-max-redirections, so issue an error and
589 ;; stop redirecting.
590 (url-http-debug "Maximum redirections reached")
591 (setf (car url-callback-arguments)
592 (nconc (list :error (list 'error 'http-redirect-limit
593 redirect-uri))
594 (car url-callback-arguments)))
595 (setq success t))))))
574 (4 ; Client error 596 (4 ; Client error
575 ;; 400 Bad Request 597 ;; 400 Bad Request
576 ;; 401 Unauthorized 598 ;; 401 Unauthorized