Function: url-http

url-http is an autoloaded and byte-compiled function defined in url-http.el.gz.

Signature

(url-http URL CALLBACK CBARGS &optional RETRY-BUFFER GATEWAY-METHOD)

Documentation

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). The current buffer when 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.

The return value of this function is the retrieval buffer.

Source Code

;; Defined in /usr/src/emacs/lisp/url/url-http.el.gz
(defun url-http (url callback cbargs &optional retry-buffer gateway-method)
  "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).  The current buffer
when 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'.

The return value of this function is the retrieval buffer."
  (cl-check-type url url "Need a pre-parsed URL.")
  (let* (;; (host (url-host (or url-using-proxy url)))
	 ;; (port (url-port (or url-using-proxy url)))
	 (nsm-noninteractive (or url-request-noninteractive
				 (and (boundp 'url-http-noninteractive)
				      url-http-noninteractive)))
         ;; The following binding is needed in url-open-stream, which
         ;; is called from url-http-find-free-connection.
         (url-current-object url)
         (connection (url-http-find-free-connection (url-host url)
                                                    (url-port url)
                                                    gateway-method))
         (mime-accept-string url-mime-accept-string)
	 (buffer (or retry-buffer
		     (generate-new-buffer
                      (format " *http %s:%d*" (url-host url) (url-port url)))))
         (referer (url-http--encode-string (url-http--get-referer url))))
    (if (not connection)
	;; Failed to open the connection for some reason
	(progn
	  (kill-buffer buffer)
	  (setq buffer nil)
          (error "Could not create connection to %s:%d" (url-host url)
                 (url-port url)))
      (with-current-buffer buffer
	(mm-disable-multibyte)
	(setq url-current-object url
	      mode-line-format "%b [%s]")

	(dolist (var '(url-http-end-of-headers
		       url-http-content-type
		       url-http-content-length
		       url-http-transfer-encoding
		       url-http-after-change-function
		       url-http-response-version
		       url-http-response-status
		       url-http-chunked-length
		       url-http-chunked-counter
		       url-http-chunked-start
		       url-callback-function
		       url-callback-arguments
		       url-show-status
		       url-http-process
		       url-http-method
		       url-http-extra-headers
		       url-http-noninteractive
		       url-http-data
		       url-http-target-url
		       url-http-no-retry
		       url-http-connection-opened
                       url-mime-accept-string
		       url-http-proxy
                       url-http-referer))
	  (set (make-local-variable var) nil))

	(setq url-http-method (or url-request-method "GET")
	      url-http-extra-headers url-request-extra-headers
	      url-http-noninteractive url-request-noninteractive
	      url-http-data url-request-data
	      url-http-process connection
	      url-http-chunked-length nil
	      url-http-chunked-start nil
	      url-http-chunked-counter 0
	      url-callback-function callback
	      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-mime-accept-string mime-accept-string
	      url-http-proxy url-using-proxy
              url-http-referer referer)

	(set-process-buffer connection buffer)
	(set-process-filter connection #'url-http-generic-filter)
	(pcase (process-status connection)
          ('connect
           ;; Asynchronous connection
           (set-process-sentinel connection 'url-http-async-sentinel))
          ('failed
           ;; Asynchronous connection failed
           (error "Could not create connection to %s:%d" (url-host url)
                  (url-port url)))
          (_
           (if (and url-http-proxy (string= "https"
                                            (url-type url-current-object)))
               (url-https-proxy-connect connection)
             (set-process-sentinel connection
                                   #'url-http-end-of-document-sentinel)
             (process-send-string connection (url-http-create-request)))))))
    buffer))