Function: url-retrieve-synchronously
url-retrieve-synchronously is an autoloaded and byte-compiled function
defined in url.el.gz.
Signature
(url-retrieve-synchronously URL &optional SILENT INHIBIT-COOKIES TIMEOUT)
Documentation
Retrieve URL synchronously.
Return the buffer containing the data, or nil if there are no data associated with it (the case for dired, info, or mailto URLs that need no further processing). URL is either a string or a parsed URL.
If SILENT is non-nil, don't do any messaging while retrieving. If INHIBIT-COOKIES is non-nil, refuse to store cookies. If TIMEOUT is passed, it should be a number that says (in seconds) how long to wait for a response before giving up.
Probably introduced at or before Emacs version 26.1.
Source Code
;; Defined in /usr/src/emacs/lisp/url/url.el.gz
;;;###autoload
(defun url-retrieve-synchronously (url &optional silent inhibit-cookies timeout)
"Retrieve URL synchronously.
Return the buffer containing the data, or nil if there are no data
associated with it (the case for dired, info, or mailto URLs that need
no further processing). URL is either a string or a parsed URL.
If SILENT is non-nil, don't do any messaging while retrieving.
If INHIBIT-COOKIES is non-nil, refuse to store cookies. If
TIMEOUT is passed, it should be a number that says (in seconds)
how long to wait for a response before giving up."
(url-do-setup)
(let* (url-asynchronous
data-buffer
(callback (lambda (&rest _args)
(setq data-buffer (current-buffer))
(url-debug 'retrieval
"Synchronous fetching done (%S)"
data-buffer)))
(start-time (current-time))
(proc-buffer (url-retrieve url callback nil silent
inhibit-cookies)))
(if (not proc-buffer)
(url-debug 'retrieval "Synchronous fetching unnecessary %s" url)
(unwind-protect
(catch 'done
(while (not data-buffer)
(when (and timeout (time-less-p timeout
(time-since start-time)))
(url-debug 'retrieval "Timed out %s (after %ss)" url
(float-time (time-since start-time)))
(throw 'done 'timeout))
(url-debug 'retrieval
"Spinning in url-retrieve-synchronously: nil (%S)"
proc-buffer)
(when-let ((redirect-buffer
(buffer-local-value 'url-redirect-buffer
proc-buffer)))
(unless (eq redirect-buffer proc-buffer)
(url-debug
'retrieval "Redirect in url-retrieve-synchronously: %S -> %S"
proc-buffer redirect-buffer)
(let (kill-buffer-query-functions)
(kill-buffer proc-buffer))
;; Accommodate hack in commit 55d1d8b.
(setq proc-buffer redirect-buffer)))
(when-let ((proc (get-buffer-process proc-buffer)))
(when (memq (process-status proc)
'(closed exit signal failed))
;; Process sentinel vagaries occasionally cause
;; url-retrieve to fail calling callback.
(unless data-buffer
(url-debug 'retrieval "Dead process %s" url)
(throw 'done 'exception))))
;; Querying over consumer internet in the US takes 100
;; ms, so split the difference.
(accept-process-output nil 0.05)))
;; Kill the process buffer on redirects.
(when (and data-buffer
(not (eq data-buffer proc-buffer)))
(let (kill-buffer-query-functions)
(kill-buffer proc-buffer)))))
data-buffer))