emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r107567: Allow url-http to handle exp


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r107567: Allow url-http to handle expired keepalive connections.
Date: Sun, 11 Mar 2012 23:12:26 +0800
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 107567
fixes bug(s): http://debbugs.gnu.org/10223
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Sun 2012-03-11 23:12:26 +0800
message:
  Allow url-http to handle expired keepalive connections.
  
  * lisp/url/url-http.el (url-http-end-of-document-sentinel): Handle
  keepalive expiry by calling url-http again.
  (url-http): New arg, for the above.
modified:
  lisp/url/ChangeLog
  lisp/url/url-http.el
=== modified file 'lisp/url/ChangeLog'
--- a/lisp/url/ChangeLog        2012-03-11 09:43:01 +0000
+++ b/lisp/url/ChangeLog        2012-03-11 15:12:26 +0000
@@ -1,3 +1,9 @@
+2012-03-11  Chong Yidong  <address@hidden>
+
+       * url-http.el (url-http-end-of-document-sentinel): Handle
+       keepalive expiry by calling url-http again (Bug#10223).
+       (url-http): New arg, for the above.
+
 2012-03-11  Devon Sean McCullough  <address@hidden>
 
        * url-http.el (url-http-find-free-connection): Don't pass a nil

=== modified file 'lisp/url/url-http.el'
--- a/lisp/url/url-http.el      2012-03-11 09:43:01 +0000
+++ b/lisp/url/url-http.el      2012-03-11 15:12:26 +0000
@@ -27,6 +27,7 @@
 (eval-when-compile (require 'cl))
 (defvar url-http-extra-headers)
 (defvar url-http-target-url)
+(defvar url-http-no-retry)
 (defvar url-http-proxy)
 (defvar url-http-connection-opened)
 (require 'url-gw)
@@ -875,19 +876,26 @@
              url-http-open-connections))
 
 (defun url-http-end-of-document-sentinel (proc why)
-  ;; Sentinel used for old HTTP/0.9 or connections we know are going
-  ;; to die as the 'end of document' notifier.
+  ;; Sentinel used to handle (i) terminated old HTTP/0.9 connections,
+  ;; and (ii) closed connection due to reusing a HTTP connection which
+  ;; we believed was still alive, but which the server closed on us.
+  ;; We handle case (ii) by calling `url-http' again.
   (url-http-debug "url-http-end-of-document-sentinel in buffer (%s)"
                  (process-buffer proc))
   (url-http-idle-sentinel proc why)
   (when (buffer-name (process-buffer proc))
     (with-current-buffer (process-buffer proc)
       (goto-char (point-min))
-      (if (not (looking-at "HTTP/"))
-         ;; HTTP/0.9 just gets passed back no matter what
-         (url-http-activate-callback)
-       (if (url-http-parse-headers)
-           (url-http-activate-callback))))))
+      (cond ((not (looking-at "HTTP/"))
+            (if url-http-no-retry
+                ;; HTTP/0.9 just gets passed back no matter what
+                (url-http-activate-callback)
+              ;; Call `url-http' again if our connection expired.
+              (erase-buffer)
+              (url-http url-current-object url-callback-function
+                        url-callback-arguments (current-buffer))))
+           ((url-http-parse-headers)
+            (url-http-activate-callback))))))
 
 (defun url-http-simple-after-change-function (st nd length)
   ;; Function used when we do NOT know how long the document is going to be
@@ -1165,11 +1173,14 @@
       (goto-char (point-max)))))
 
 ;;;###autoload
-(defun url-http (url callback cbargs)
+(defun url-http (url callback cbargs &optional retry-buffer)
   "Retrieve URL via HTTP asynchronously.
 URL must be a parsed URL.  See `url-generic-parse-url' for details.
 When retrieval is completed, the function CALLBACK is executed with
-CBARGS as the arguments."
+CBARGS as the arguments.
+
+Optional arg RETRY-BUFFER, if non-nil, specifies the buffer of a
+previous `url-http' call, which is being re-attempted."
   (check-type url vector "Need a pre-parsed URL.")
   (declare (special url-current-object
                    url-http-end-of-headers
@@ -1190,7 +1201,8 @@
   (let* ((host (url-host (or url-using-proxy url)))
         (port (url-port (or url-using-proxy url)))
         (connection (url-http-find-free-connection host port))
-        (buffer (generate-new-buffer (format " *http %s:%d*" host port))))
+        (buffer (or retry-buffer
+                    (generate-new-buffer (format " *http %s:%d*" host port)))))
     (if (not connection)
        ;; Failed to open the connection for some reason
        (progn
@@ -1220,6 +1232,7 @@
                       url-http-extra-headers
                       url-http-data
                       url-http-target-url
+                      url-http-no-retry
                       url-http-connection-opened
                       url-http-proxy))
          (set (make-local-variable var) nil))
@@ -1235,6 +1248,7 @@
              url-callback-arguments cbargs
              url-http-after-change-function 
'url-http-wait-for-headers-change-function
              url-http-target-url url-current-object
+             url-http-no-retry retry-buffer
              url-http-connection-opened nil
              url-http-proxy url-using-proxy)
 
@@ -1261,6 +1275,7 @@
     (with-current-buffer (process-buffer proc)
       (cond
        (url-http-connection-opened
+       (setq url-http-no-retry t)
        (url-http-end-of-document-sentinel proc why))
        ((string= (substring why 0 4) "open")
        (setq url-http-connection-opened t)


reply via email to

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