Spelling fixes.
[bpt/emacs.git] / lisp / url / url-http.el
index f1b687c..a9ff042 100644 (file)
@@ -1,7 +1,6 @@
 ;;; url-http.el --- HTTP retrieval routines
 
-;; Copyright (C) 1999, 2001, 2004, 2005, 2006, 2007, 2008,
-;;   2009, 2010, 2011  Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2001, 2004-2011  Free Software Foundation, Inc.
 
 ;; Author: Bill Perry <wmperry@gnu.org>
 ;; Keywords: comm, data, processes
@@ -181,6 +180,10 @@ request.")
                   ;; Drop the temp buffer link before killing the buffer.
                   (set-process-buffer proc nil))
                  proc)
+            ;; If there was an error on connect, make sure we don't
+            ;; get queried.
+            (when (get-buffer-process buf)
+              (set-process-query-on-exit-flag (get-buffer-process buf) nil))
              (kill-buffer buf)))))))
 
 ;; Building an HTTP request
@@ -254,7 +257,7 @@ request.")
     (if (not (equal extra-headers ""))
        (setq extra-headers (concat extra-headers "\r\n")))
 
-    ;; This was done with a call to `format'.  Concatting parts has
+    ;; This was done with a call to `format'.  Concatenating parts has
     ;; the advantage of keeping the parts of each header together and
     ;; allows us to elide null lines directly, at the cost of making
     ;; the layout less clear.
@@ -339,7 +342,9 @@ request.")
              ;; End request
              "\r\n"
              ;; Any data
-             url-http-data "\r\n"))
+             url-http-data
+            ;; If `url-http-data' is nil, avoid two CRLFs (Bug#8931).
+            (if url-http-data "\r\n")))
            ""))
     (url-http-debug "Request is: \n%s" request)
     request))
@@ -564,16 +569,8 @@ should be shown to the user."
            ;; automatically redirect the request unless it can be
            ;; confirmed by the user, since this might change the
            ;; conditions under which the request was issued.
-           (if (member url-http-method '("HEAD" "GET"))
-               ;; Automatic redirection is ok
-               nil
-             ;; It is just too big of a pain in the ass to get this
-             ;; prompt all the time.  We will just silently lose our
-             ;; data and convert to a GET method.
-             (url-http-debug "Converting `%s' request to `GET' because of REDIRECT(%d)"
-                             url-http-method url-http-response-status)
-             (setq url-http-method "GET"
-                   url-http-data nil)))
+           (unless (member url-http-method '("HEAD" "GET"))
+             (setq redirect-uri nil)))
           (see-other                   ; 303
            ;; The response to the request can be found under a different
            ;; URI and SHOULD be retrieved using a GET method on that
@@ -705,7 +702,7 @@ should be shown to the user."
         (not-acceptable                ; 406
          ;; The resource identified by the request is only capable of
          ;; generating response entities which have content
-         ;; characteristics notcceptable according to the accept
+         ;; characteristics not acceptable according to the accept
          ;; headers sent in the request.
          (setq success t))
         (proxy-authentication-required ; 407
@@ -724,7 +721,7 @@ should be shown to the user."
          ;; The request could not be completed due to a conflict with
          ;; the current state of the resource.  This code is only
          ;; allowed in situations where it is expected that the user
-         ;; mioght be able to resolve the conflict and resubmit the
+         ;; might be able to resolve the conflict and resubmit the
          ;; request.  The response body SHOULD include enough
          ;; information for the user to recognize the source of the
          ;; conflict.
@@ -1035,10 +1032,11 @@ the end of the document."
                    url-http-response-status))
   (url-http-debug "url-http-wait-for-headers-change-function (%s)"
                  (buffer-name))
-  (when (not (bobp))
-    (let ((end-of-headers nil)
-         (old-http nil)
-         (content-length nil))
+  (let ((end-of-headers nil)
+       (old-http nil)
+       (process-buffer (current-buffer))
+       (content-length nil))
+    (when (not (bobp))
       (goto-char (point-min))
       (if (and (looking-at ".*\n")     ; have one line at least
               (not (looking-at "^HTTP/[1-9]\\.[0-9]")))
@@ -1059,24 +1057,25 @@ the end of the document."
          ;; Haven't seen the end of the headers yet, need to wait
          ;; for more data to arrive.
          nil
-       (if old-http
-           (message "HTTP/0.9 How I hate thee!")
-         (progn
-           (url-http-parse-response)
-           (mail-narrow-to-head)
-           ;;(narrow-to-region (point-min) url-http-end-of-headers)
-           (setq url-http-transfer-encoding (mail-fetch-field
-                                             "transfer-encoding")
-                 url-http-content-type (mail-fetch-field "content-type"))
-           (if (mail-fetch-field "content-length")
-               (setq url-http-content-length
-                     (string-to-number (mail-fetch-field "content-length"))))
-           (widen)))
+       (unless old-http
+         (url-http-parse-response)
+         (mail-narrow-to-head)
+         (setq url-http-transfer-encoding (mail-fetch-field
+                                           "transfer-encoding")
+               url-http-content-type (mail-fetch-field "content-type"))
+         (if (mail-fetch-field "content-length")
+             (setq url-http-content-length
+                   (string-to-number (mail-fetch-field "content-length"))))
+         (widen))
        (when url-http-transfer-encoding
          (setq url-http-transfer-encoding
                (downcase url-http-transfer-encoding)))
 
        (cond
+        ((null url-http-response-status)
+         ;; We got back a headerless malformed response from the
+         ;; server.
+         (url-http-activate-callback))
         ((or (= url-http-response-status 204)
              (= url-http-response-status 205))
          (url-http-debug "%d response must have headers only (%s)."
@@ -1093,7 +1092,7 @@ the end of the document."
            (url-http-activate-callback)))
         ((string= "CONNECT" url-http-method)
          ;; A CONNECT request is finished, but we cannot stick this
-         ;; back on the free connectin list
+         ;; back on the free connection list
          (url-http-debug "CONNECT request must have headers only.")
          (when (url-http-parse-headers)
            (url-http-activate-callback)))
@@ -1152,8 +1151,9 @@ the end of the document."
                'url-http-simple-after-change-function)))))
     ;; We are still at the beginning of the buffer... must just be
     ;; waiting for a response.
-    (url-http-debug "Spinning waiting for headers..."))
-  (goto-char (point-max)))
+    (url-http-debug "Spinning waiting for headers...")
+    (when (eq process-buffer (current-buffer))
+      (goto-char (point-max)))))
 
 ;;;###autoload
 (defun url-http (url callback cbargs)
@@ -1170,6 +1170,7 @@ CBARGS as the arguments."
                    url-http-after-change-function
                    url-callback-function
                    url-callback-arguments
+                   url-show-status
                    url-http-method
                    url-http-extra-headers
                    url-http-data
@@ -1204,6 +1205,7 @@ CBARGS as the arguments."
                       url-http-chunked-start
                       url-callback-function
                       url-callback-arguments
+                      url-show-status
                       url-http-process
                       url-http-method
                       url-http-extra-headers
@@ -1253,7 +1255,11 @@ CBARGS as the arguments."
        (url-http-end-of-document-sentinel proc why))
        ((string= (substring why 0 4) "open")
        (setq url-http-connection-opened t)
-       (process-send-string proc (url-http-create-request)))
+       (condition-case error
+           (process-send-string proc (url-http-create-request))
+         (file-error
+          (setq url-http-connection-opened nil)
+          (message "HTTP error: %s" error))))
        (t
        (setf (car url-callback-arguments)
              (nconc (list :error (list 'error 'connection-failed why
@@ -1453,5 +1459,4 @@ p3p
 
 (provide 'url-http)
 
-;; arch-tag: ba7c59ae-c0f4-4a31-9617-d85f221732ee
 ;;; url-http.el ends here