aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2012-03-11 23:12:26 +0800
committerChong Yidong2012-03-11 23:12:26 +0800
commit091006330e4bf8a8e3a98fd2711372bb1a43eeee (patch)
tree9d5fda87262bc71ca51bc86c36c733f99325ce26
parentc491fa419042fa7768fd25db758d2db7f8cf547c (diff)
downloademacs-091006330e4bf8a8e3a98fd2711372bb1a43eeee.tar.gz
emacs-091006330e4bf8a8e3a98fd2711372bb1a43eeee.zip
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. Fixes: debbugs:10223
-rw-r--r--lisp/url/ChangeLog6
-rw-r--r--lisp/url/url-http.el35
2 files changed, 31 insertions, 10 deletions
diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog
index 6f65ab57fe6..960649bdbc9 100644
--- a/lisp/url/ChangeLog
+++ b/lisp/url/ChangeLog
@@ -1,3 +1,9 @@
12012-03-11 Chong Yidong <cyd@gnu.org>
2
3 * url-http.el (url-http-end-of-document-sentinel): Handle
4 keepalive expiry by calling url-http again (Bug#10223).
5 (url-http): New arg, for the above.
6
12012-03-11 Devon Sean McCullough <emacs-hacker2012@jovi.net> 72012-03-11 Devon Sean McCullough <emacs-hacker2012@jovi.net>
2 8
3 * url-http.el (url-http-find-free-connection): Don't pass a nil 9 * url-http.el (url-http-find-free-connection): Don't pass a nil
diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el
index 36e35593385..a4726489814 100644
--- a/lisp/url/url-http.el
+++ b/lisp/url/url-http.el
@@ -27,6 +27,7 @@
27(eval-when-compile (require 'cl)) 27(eval-when-compile (require 'cl))
28(defvar url-http-extra-headers) 28(defvar url-http-extra-headers)
29(defvar url-http-target-url) 29(defvar url-http-target-url)
30(defvar url-http-no-retry)
30(defvar url-http-proxy) 31(defvar url-http-proxy)
31(defvar url-http-connection-opened) 32(defvar url-http-connection-opened)
32(require 'url-gw) 33(require 'url-gw)
@@ -875,19 +876,26 @@ should be shown to the user."
875 url-http-open-connections)) 876 url-http-open-connections))
876 877
877(defun url-http-end-of-document-sentinel (proc why) 878(defun url-http-end-of-document-sentinel (proc why)
878 ;; Sentinel used for old HTTP/0.9 or connections we know are going 879 ;; Sentinel used to handle (i) terminated old HTTP/0.9 connections,
879 ;; to die as the 'end of document' notifier. 880 ;; and (ii) closed connection due to reusing a HTTP connection which
881 ;; we believed was still alive, but which the server closed on us.
882 ;; We handle case (ii) by calling `url-http' again.
880 (url-http-debug "url-http-end-of-document-sentinel in buffer (%s)" 883 (url-http-debug "url-http-end-of-document-sentinel in buffer (%s)"
881 (process-buffer proc)) 884 (process-buffer proc))
882 (url-http-idle-sentinel proc why) 885 (url-http-idle-sentinel proc why)
883 (when (buffer-name (process-buffer proc)) 886 (when (buffer-name (process-buffer proc))
884 (with-current-buffer (process-buffer proc) 887 (with-current-buffer (process-buffer proc)
885 (goto-char (point-min)) 888 (goto-char (point-min))
886 (if (not (looking-at "HTTP/")) 889 (cond ((not (looking-at "HTTP/"))
887 ;; HTTP/0.9 just gets passed back no matter what 890 (if url-http-no-retry
888 (url-http-activate-callback) 891 ;; HTTP/0.9 just gets passed back no matter what
889 (if (url-http-parse-headers) 892 (url-http-activate-callback)
890 (url-http-activate-callback)))))) 893 ;; Call `url-http' again if our connection expired.
894 (erase-buffer)
895 (url-http url-current-object url-callback-function
896 url-callback-arguments (current-buffer))))
897 ((url-http-parse-headers)
898 (url-http-activate-callback))))))
891 899
892(defun url-http-simple-after-change-function (st nd length) 900(defun url-http-simple-after-change-function (st nd length)
893 ;; Function used when we do NOT know how long the document is going to be 901 ;; Function used when we do NOT know how long the document is going to be
@@ -1165,11 +1173,14 @@ the end of the document."
1165 (goto-char (point-max))))) 1173 (goto-char (point-max)))))
1166 1174
1167;;;###autoload 1175;;;###autoload
1168(defun url-http (url callback cbargs) 1176(defun url-http (url callback cbargs &optional retry-buffer)
1169 "Retrieve URL via HTTP asynchronously. 1177 "Retrieve URL via HTTP asynchronously.
1170URL must be a parsed URL. See `url-generic-parse-url' for details. 1178URL must be a parsed URL. See `url-generic-parse-url' for details.
1171When retrieval is completed, the function CALLBACK is executed with 1179When retrieval is completed, the function CALLBACK is executed with
1172CBARGS as the arguments." 1180CBARGS as the arguments.
1181
1182Optional arg RETRY-BUFFER, if non-nil, specifies the buffer of a
1183previous `url-http' call, which is being re-attempted."
1173 (check-type url vector "Need a pre-parsed URL.") 1184 (check-type url vector "Need a pre-parsed URL.")
1174 (declare (special url-current-object 1185 (declare (special url-current-object
1175 url-http-end-of-headers 1186 url-http-end-of-headers
@@ -1190,7 +1201,8 @@ CBARGS as the arguments."
1190 (let* ((host (url-host (or url-using-proxy url))) 1201 (let* ((host (url-host (or url-using-proxy url)))
1191 (port (url-port (or url-using-proxy url))) 1202 (port (url-port (or url-using-proxy url)))
1192 (connection (url-http-find-free-connection host port)) 1203 (connection (url-http-find-free-connection host port))
1193 (buffer (generate-new-buffer (format " *http %s:%d*" host port)))) 1204 (buffer (or retry-buffer
1205 (generate-new-buffer (format " *http %s:%d*" host port)))))
1194 (if (not connection) 1206 (if (not connection)
1195 ;; Failed to open the connection for some reason 1207 ;; Failed to open the connection for some reason
1196 (progn 1208 (progn
@@ -1220,6 +1232,7 @@ CBARGS as the arguments."
1220 url-http-extra-headers 1232 url-http-extra-headers
1221 url-http-data 1233 url-http-data
1222 url-http-target-url 1234 url-http-target-url
1235 url-http-no-retry
1223 url-http-connection-opened 1236 url-http-connection-opened
1224 url-http-proxy)) 1237 url-http-proxy))
1225 (set (make-local-variable var) nil)) 1238 (set (make-local-variable var) nil))
@@ -1235,6 +1248,7 @@ CBARGS as the arguments."
1235 url-callback-arguments cbargs 1248 url-callback-arguments cbargs
1236 url-http-after-change-function 'url-http-wait-for-headers-change-function 1249 url-http-after-change-function 'url-http-wait-for-headers-change-function
1237 url-http-target-url url-current-object 1250 url-http-target-url url-current-object
1251 url-http-no-retry retry-buffer
1238 url-http-connection-opened nil 1252 url-http-connection-opened nil
1239 url-http-proxy url-using-proxy) 1253 url-http-proxy url-using-proxy)
1240 1254
@@ -1261,6 +1275,7 @@ CBARGS as the arguments."
1261 (with-current-buffer (process-buffer proc) 1275 (with-current-buffer (process-buffer proc)
1262 (cond 1276 (cond
1263 (url-http-connection-opened 1277 (url-http-connection-opened
1278 (setq url-http-no-retry t)
1264 (url-http-end-of-document-sentinel proc why)) 1279 (url-http-end-of-document-sentinel proc why))
1265 ((string= (substring why 0 4) "open") 1280 ((string= (substring why 0 4) "open")
1266 (setq url-http-connection-opened t) 1281 (setq url-http-connection-opened t)