diff options
| author | Magnus Henoch | 2006-11-26 12:50:15 +0000 |
|---|---|---|
| committer | Magnus Henoch | 2006-11-26 12:50:15 +0000 |
| commit | 57babe17161b695f9e23d6d206c1b7c8f40de72a (patch) | |
| tree | 37887e8f65170317068f9cde579e50aec73f51fe | |
| parent | 947ebc5fc5119d075eccd50a9868d6fa2d0d6893 (diff) | |
| download | emacs-57babe17161b695f9e23d6d206c1b7c8f40de72a.tar.gz emacs-57babe17161b695f9e23d6d206c1b7c8f40de72a.zip | |
(url-http-wait-for-headers-change-function): Use `when' instead of
`if' when possible.
| -rw-r--r-- | lisp/url/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/url/url-http.el | 226 |
2 files changed, 117 insertions, 114 deletions
diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog index 597c27bed67..2175a4e53d0 100644 --- a/lisp/url/ChangeLog +++ b/lisp/url/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2006-11-26 Magnus Henoch <mange@freemail.hu> | ||
| 2 | |||
| 3 | * url-http.el (url-http-wait-for-headers-change-function): Use | ||
| 4 | `when' instead of `if' when possible. | ||
| 5 | |||
| 1 | 2006-11-23 Diane Murray <disumu@x3y2z1.net> | 6 | 2006-11-23 Diane Murray <disumu@x3y2z1.net> |
| 2 | 7 | ||
| 3 | * url-http.el (url-http-content-length-after-change-function): Use | 8 | * url-http.el (url-http-content-length-after-change-function): Use |
diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el index ff8bb45d738..2fb608d2b92 100644 --- a/lisp/url/url-http.el +++ b/lisp/url/url-http.el | |||
| @@ -928,123 +928,121 @@ the end of the document." | |||
| 928 | url-http-response-status)) | 928 | url-http-response-status)) |
| 929 | (url-http-debug "url-http-wait-for-headers-change-function (%s)" | 929 | (url-http-debug "url-http-wait-for-headers-change-function (%s)" |
| 930 | (buffer-name)) | 930 | (buffer-name)) |
| 931 | (if (not (bobp)) | 931 | (when (not (bobp)) |
| 932 | (let ((end-of-headers nil) | 932 | (let ((end-of-headers nil) |
| 933 | (old-http nil) | 933 | (old-http nil) |
| 934 | (content-length nil)) | 934 | (content-length nil)) |
| 935 | (goto-char (point-min)) | 935 | (goto-char (point-min)) |
| 936 | (if (and (looking-at ".*\n") ; have one line at least | 936 | (if (and (looking-at ".*\n") ; have one line at least |
| 937 | (not (looking-at "^HTTP/[1-9]\\.[0-9]"))) | 937 | (not (looking-at "^HTTP/[1-9]\\.[0-9]"))) |
| 938 | ;; Not HTTP/x.y data, must be 0.9 | 938 | ;; Not HTTP/x.y data, must be 0.9 |
| 939 | ;; God, I wish this could die. | 939 | ;; God, I wish this could die. |
| 940 | (setq end-of-headers t | 940 | (setq end-of-headers t |
| 941 | url-http-end-of-headers 0 | 941 | url-http-end-of-headers 0 |
| 942 | old-http t) | 942 | old-http t) |
| 943 | (if (re-search-forward "^\r*$" nil t) | 943 | (when (re-search-forward "^\r*$" nil t) |
| 944 | ;; Saw the end of the headers | 944 | ;; Saw the end of the headers |
| 945 | (progn | 945 | (url-http-debug "Saw end of headers... (%s)" (buffer-name)) |
| 946 | (url-http-debug "Saw end of headers... (%s)" (buffer-name)) | 946 | (setq url-http-end-of-headers (set-marker (make-marker) |
| 947 | (setq url-http-end-of-headers (set-marker (make-marker) | 947 | (point)) |
| 948 | (point)) | 948 | end-of-headers t) |
| 949 | end-of-headers t) | 949 | (url-http-clean-headers))) |
| 950 | (url-http-clean-headers)))) | 950 | |
| 951 | 951 | (if (not end-of-headers) | |
| 952 | (if (not end-of-headers) | 952 | ;; Haven't seen the end of the headers yet, need to wait |
| 953 | ;; Haven't seen the end of the headers yet, need to wait | 953 | ;; for more data to arrive. |
| 954 | ;; for more data to arrive. | 954 | nil |
| 955 | nil | 955 | (if old-http |
| 956 | (if old-http | 956 | (message "HTTP/0.9 How I hate thee!") |
| 957 | (message "HTTP/0.9 How I hate thee!") | 957 | (progn |
| 958 | (progn | 958 | (url-http-parse-response) |
| 959 | (url-http-parse-response) | 959 | (mail-narrow-to-head) |
| 960 | (mail-narrow-to-head) | 960 | ;;(narrow-to-region (point-min) url-http-end-of-headers) |
| 961 | ;;(narrow-to-region (point-min) url-http-end-of-headers) | 961 | (setq url-http-transfer-encoding (mail-fetch-field |
| 962 | (setq url-http-transfer-encoding (mail-fetch-field | 962 | "transfer-encoding") |
| 963 | "transfer-encoding") | 963 | url-http-content-type (mail-fetch-field "content-type")) |
| 964 | url-http-content-type (mail-fetch-field "content-type")) | 964 | (if (mail-fetch-field "content-length") |
| 965 | (if (mail-fetch-field "content-length") | 965 | (setq url-http-content-length |
| 966 | (setq url-http-content-length | 966 | (string-to-number (mail-fetch-field "content-length")))) |
| 967 | (string-to-number (mail-fetch-field "content-length")))) | 967 | (widen))) |
| 968 | (widen))) | 968 | (when url-http-transfer-encoding |
| 969 | (if url-http-transfer-encoding | 969 | (setq url-http-transfer-encoding |
| 970 | (setq url-http-transfer-encoding | 970 | (downcase url-http-transfer-encoding))) |
| 971 | (downcase url-http-transfer-encoding))) | 971 | |
| 972 | 972 | (cond | |
| 973 | (cond | 973 | ((or (= url-http-response-status 204) |
| 974 | ((or (= url-http-response-status 204) | 974 | (= url-http-response-status 205)) |
| 975 | (= url-http-response-status 205)) | 975 | (url-http-debug "%d response must have headers only (%s)." |
| 976 | (url-http-debug "%d response must have headers only (%s)." | 976 | url-http-response-status (buffer-name)) |
| 977 | url-http-response-status (buffer-name)) | 977 | (when (url-http-parse-headers) |
| 978 | (if (url-http-parse-headers) | 978 | (url-http-activate-callback))) |
| 979 | (url-http-activate-callback))) | 979 | ((string= "HEAD" url-http-method) |
| 980 | ((string= "HEAD" url-http-method) | 980 | ;; A HEAD request is _ALWAYS_ terminated by the header |
| 981 | ;; A HEAD request is _ALWAYS_ terminated by the header | 981 | ;; information, regardless of any entity headers, |
| 982 | ;; information, regardless of any entity headers, | 982 | ;; according to section 4.4 of the HTTP/1.1 draft. |
| 983 | ;; according to section 4.4 of the HTTP/1.1 draft. | 983 | (url-http-debug "HEAD request must have headers only (%s)." |
| 984 | (url-http-debug "HEAD request must have headers only (%s)." | 984 | (buffer-name)) |
| 985 | (buffer-name)) | 985 | (when (url-http-parse-headers) |
| 986 | (if (url-http-parse-headers) | 986 | (url-http-activate-callback))) |
| 987 | (url-http-activate-callback))) | 987 | ((string= "CONNECT" url-http-method) |
| 988 | ((string= "CONNECT" url-http-method) | 988 | ;; A CONNECT request is finished, but we cannot stick this |
| 989 | ;; A CONNECT request is finished, but we cannot stick this | 989 | ;; back on the free connectin list |
| 990 | ;; back on the free connectin list | 990 | (url-http-debug "CONNECT request must have headers only.") |
| 991 | (url-http-debug "CONNECT request must have headers only.") | 991 | (when (url-http-parse-headers) |
| 992 | (if (url-http-parse-headers) | 992 | (url-http-activate-callback))) |
| 993 | (url-http-activate-callback))) | 993 | ((equal url-http-response-status 304) |
| 994 | ((equal url-http-response-status 304) | 994 | ;; Only allowed to have a header section. We have to handle |
| 995 | ;; Only allowed to have a header section. We have to handle | 995 | ;; this here instead of in url-http-parse-headers because if |
| 996 | ;; this here instead of in url-http-parse-headers because if | 996 | ;; you have a cached copy of something without a known |
| 997 | ;; you have a cached copy of something without a known | 997 | ;; content-length, and try to retrieve it from the cache, we'd |
| 998 | ;; content-length, and try to retrieve it from the cache, we'd | 998 | ;; fall into the 'being dumb' section and wait for the |
| 999 | ;; fall into the 'being dumb' section and wait for the | 999 | ;; connection to terminate, which means we'd wait for 10 |
| 1000 | ;; connection to terminate, which means we'd wait for 10 | 1000 | ;; seconds for the keep-alives to time out on some servers. |
| 1001 | ;; seconds for the keep-alives to time out on some servers. | 1001 | (when (url-http-parse-headers) |
| 1002 | (if (url-http-parse-headers) | 1002 | (url-http-activate-callback))) |
| 1003 | (url-http-activate-callback))) | 1003 | (old-http |
| 1004 | (old-http | 1004 | ;; HTTP/0.9 always signaled end-of-connection by closing the |
| 1005 | ;; HTTP/0.9 always signaled end-of-connection by closing the | 1005 | ;; connection. |
| 1006 | ;; connection. | 1006 | (url-http-debug |
| 1007 | "Saw HTTP/0.9 response, connection closed means end of document.") | ||
| 1008 | (setq url-http-after-change-function | ||
| 1009 | 'url-http-simple-after-change-function)) | ||
| 1010 | ((equal url-http-transfer-encoding "chunked") | ||
| 1011 | (url-http-debug "Saw chunked encoding.") | ||
| 1012 | (setq url-http-after-change-function | ||
| 1013 | 'url-http-chunked-encoding-after-change-function) | ||
| 1014 | (when (> nd url-http-end-of-headers) | ||
| 1007 | (url-http-debug | 1015 | (url-http-debug |
| 1008 | "Saw HTTP/0.9 response, connection closed means end of document.") | 1016 | "Calling initial chunked-encoding for extra data at end of headers") |
| 1009 | (setq url-http-after-change-function | 1017 | (url-http-chunked-encoding-after-change-function |
| 1010 | 'url-http-simple-after-change-function)) | 1018 | (marker-position url-http-end-of-headers) nd |
| 1011 | ((equal url-http-transfer-encoding "chunked") | 1019 | (- nd url-http-end-of-headers)))) |
| 1012 | (url-http-debug "Saw chunked encoding.") | 1020 | ((integerp url-http-content-length) |
| 1013 | (setq url-http-after-change-function | 1021 | (url-http-debug |
| 1014 | 'url-http-chunked-encoding-after-change-function) | 1022 | "Got a content-length, being smart about document end.") |
| 1015 | (if (> nd url-http-end-of-headers) | 1023 | (setq url-http-after-change-function |
| 1016 | (progn | 1024 | 'url-http-content-length-after-change-function) |
| 1017 | (url-http-debug | 1025 | (cond |
| 1018 | "Calling initial chunked-encoding for extra data at end of headers") | 1026 | ((= 0 url-http-content-length) |
| 1019 | (url-http-chunked-encoding-after-change-function | 1027 | ;; We got a NULL body! Activate the callback |
| 1020 | (marker-position url-http-end-of-headers) nd | 1028 | ;; immediately! |
| 1021 | (- nd url-http-end-of-headers))))) | ||
| 1022 | ((integerp url-http-content-length) | ||
| 1023 | (url-http-debug | 1029 | (url-http-debug |
| 1024 | "Got a content-length, being smart about document end.") | 1030 | "Got 0-length content-length, activating callback immediately.") |
| 1025 | (setq url-http-after-change-function | 1031 | (when (url-http-parse-headers) |
| 1026 | 'url-http-content-length-after-change-function) | 1032 | (url-http-activate-callback))) |
| 1027 | (cond | 1033 | ((> nd url-http-end-of-headers) |
| 1028 | ((= 0 url-http-content-length) | 1034 | ;; Have some leftover data |
| 1029 | ;; We got a NULL body! Activate the callback | 1035 | (url-http-debug "Calling initial content-length for extra data at end of headers") |
| 1030 | ;; immediately! | 1036 | (url-http-content-length-after-change-function |
| 1031 | (url-http-debug | 1037 | (marker-position url-http-end-of-headers) |
| 1032 | "Got 0-length content-length, activating callback immediately.") | 1038 | nd |
| 1033 | (if (url-http-parse-headers) | 1039 | (- nd url-http-end-of-headers))) |
| 1034 | (url-http-activate-callback))) | ||
| 1035 | ((> nd url-http-end-of-headers) | ||
| 1036 | ;; Have some leftover data | ||
| 1037 | (url-http-debug "Calling initial content-length for extra data at end of headers") | ||
| 1038 | (url-http-content-length-after-change-function | ||
| 1039 | (marker-position url-http-end-of-headers) | ||
| 1040 | nd | ||
| 1041 | (- nd url-http-end-of-headers))) | ||
| 1042 | (t | ||
| 1043 | nil))) | ||
| 1044 | (t | 1040 | (t |
| 1045 | (url-http-debug "No content-length, being dumb.") | 1041 | nil))) |
| 1046 | (setq url-http-after-change-function | 1042 | (t |
| 1047 | 'url-http-simple-after-change-function))))) | 1043 | (url-http-debug "No content-length, being dumb.") |
| 1044 | (setq url-http-after-change-function | ||
| 1045 | 'url-http-simple-after-change-function))))) | ||
| 1048 | ;; We are still at the beginning of the buffer... must just be | 1046 | ;; We are still at the beginning of the buffer... must just be |
| 1049 | ;; waiting for a response. | 1047 | ;; waiting for a response. |
| 1050 | (url-http-debug "Spinning waiting for headers...")) | 1048 | (url-http-debug "Spinning waiting for headers...")) |