]> code.delx.au - gnu-emacs/blobdiff - lisp/url/url-http.el
Merge emacs-25 into master (using imerge)
[gnu-emacs] / lisp / url / url-http.el
index 34d325acf56a526b653b9bbfc42d0023ef12cc4e..36cc2f32bbcd3be3aba4c89076c6fc71921b897d 100644 (file)
@@ -1,6 +1,6 @@
 ;;; url-http.el --- HTTP retrieval routines
 
-;; Copyright (C) 1999, 2001, 2004-2014 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2001, 2004-2015 Free Software Foundation, Inc.
 
 ;; Author: Bill Perry <wmperry@gnu.org>
 ;; Maintainer: emacs-devel@gnu.org
@@ -25,8 +25,9 @@
 
 ;;; Code:
 
+(require 'cl-lib)
+(require 'puny)
 (eval-when-compile
-  (require 'cl-lib)
   (require 'subr-x))
 
 (defvar url-callback-arguments)
@@ -135,17 +136,6 @@ request.")
     (507 insufficient-storage            "Insufficient storage"))
   "The HTTP return codes and their text.")
 
-(defcustom url-user-agent (format "User-Agent: %sURL/%s\r\n"
-                                 (if url-package-name
-                                     (concat url-package-name "/"
-                                             url-package-version " ")
-                                   "") url-version)
-  "User Agent used by the URL package."
-  :type '(choice (string :tag "A static User-Agent string")
-                 (function :tag "Call a function to get the User-Agent string"))
-  :version "25.1"
-  :group 'url)
-
 ;(eval-when-compile
 ;; These are all macros so that they are hidden from external sight
 ;; when the file is byte-compiled.
@@ -318,8 +308,9 @@ request.")
                      (url-scheme-get-property
                       (url-type url-http-target-url) 'default-port))
                  (format
-                  "Host: %s:%d\r\n" host (url-port url-http-target-url))
-               (format "Host: %s\r\n" host))
+                  "Host: %s:%d\r\n" (puny-encode-domain host)
+                  (url-port url-http-target-url))
+               (format "Host: %s\r\n" (puny-encode-domain host)))
              ;; Who its from
              (if url-personal-mail-address
                  (concat
@@ -431,7 +422,7 @@ Return the number of characters removed."
        (progn
          (widen)
          (goto-char (point-max))
-         (insert "<hr>Sorry, but I do not know how to handle " type
+         (insert "<hr>Sorry, but I do not know how to handle " (or type auth url "")
                  " authentication.  If you'd like to write it,"
                  " please use M-x report-emacs-bug RET.<hr>")
           ;; We used to set a `status' var (declared "special") but I can't
@@ -485,6 +476,8 @@ work correctly."
     )
   )
 
+(declare-function gnutls-peer-status "gnutls.c" (proc))
+
 (defun url-http-parse-headers ()
  "Parse and handle HTTP specific headers.
 Return t if and only if the current buffer is still active and
@@ -644,6 +637,12 @@ should be shown to the user."
                ;; compute the redirection relative to the URL of the proxy.
               (setq redirect-uri
                     (url-expand-file-name redirect-uri url-http-target-url)))
+          ;; Do not automatically include an authorization header in the
+          ;; redirect.  If needed it will be regenerated by the relevant
+          ;; auth scheme when the new request happens.
+          (setq url-http-extra-headers
+                (cl-remove "Authorization"
+                           url-http-extra-headers :key 'car :test 'equal))
            (let ((url-request-method url-http-method)
                 (url-request-data url-http-data)
                 (url-request-extra-headers url-http-extra-headers))
@@ -978,7 +977,7 @@ the callback to be triggered."
            (url-http-activate-callback)))))
 
 (defun url-http-chunked-encoding-after-change-function (st nd length)
-  "Function used when dealing with 'chunked' encoding.
+  "Function used when dealing with chunked encoding.
 Cannot give a sophisticated percentage, but we need a different
 function to look for the special 0-length chunk that signifies
 the end of the document."
@@ -1059,7 +1058,7 @@ the end of the document."
                  (when (looking-at "\r?\n")
                    (url-http-debug "Removing terminator of last chunk")
                    (delete-region (match-beginning 0) (match-end 0)))
-                 (if (re-search-forward "^\r*$" nil t)
+                 (if (re-search-forward "^\r?\n" nil t)
                      (url-http-debug "Saw end of trailers..."))
                  (if (url-http-parse-headers)
                      (url-http-activate-callback))))))))))
@@ -1198,17 +1197,20 @@ the end of the document."
   "Retrieve URL via HTTP asynchronously.
 URL must be a parsed URL.  See `url-generic-parse-url' for details.
 
-When retrieval is completed, execute the function CALLBACK, passing it
-an updated value of CBARGS as arguments.  The first element in CBARGS
-should be a plist describing what has happened so far during the
-request, as described in the docstring of `url-retrieve' (if in
-doubt, specify nil).
+When retrieval is completed, execute the function CALLBACK,
+passing it an updated value of CBARGS as arguments.  The first
+element in CBARGS should be a plist describing what has happened
+so far during the request, as described in the docstring of
+`url-retrieve' (if in doubt, specify nil).  The current buffer
+then CALLBACK is executed is the retrieval buffer.
 
 Optional arg RETRY-BUFFER, if non-nil, specifies the buffer of a
 previous `url-http' call, which is being re-attempted.
 
 Optional arg GATEWAY-METHOD specifies the gateway to be used,
-overriding the value of `url-gateway-method'."
+overriding the value of `url-gateway-method'.
+
+The return value of this function is the retrieval buffer."
   (cl-check-type url vector "Need a pre-parsed URL.")
   (let* ((host (url-host (or url-using-proxy url)))
         (port (url-port (or url-using-proxy url)))