aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authormooseyboots <66318400+mooseyboots@users.noreply.github.com>2021-12-21 10:17:26 +0100
committerGitHub <noreply@github.com>2021-12-21 10:17:26 +0100
commitd4c0d2a2a3013136f5b1fea40ae1e7022f461dd9 (patch)
treef00f0fa46e2e2cf90f6ef70fdf182cc5e5382a94 /lisp
parentede05a509ce7b0ae95cb71b20e2516e46038d038 (diff)
parent34d3b220fedd62b00b605cdc773f66de21c2b53f (diff)
Merge pull request #230 from ieure/ieure/http-timeouts
Set a HTTP timeout.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-http.el11
1 files changed, 9 insertions, 2 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index 7be4467..04a2235 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -35,6 +35,9 @@
(defvar mastodon-http--api-version "v1")
+(defconst mastodon-http--timeout 5
+ "HTTP request timeout, in seconds. Has no effect on Emacs < 26.1.")
+
(defun mastodon-http--api (endpoint)
"Return Mastondon API URL for ENDPOINT."
(concat mastodon-instance-url "/api/"
@@ -86,7 +89,9 @@ Authorization header is included by default unless UNAUTHENTICED-P is non-nil."
`(("Authorization" . ,(concat "Bearer " (mastodon-auth--access-token)))))
headers)))
(with-temp-buffer
- (url-retrieve-synchronously url))))
+ (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4)
+ (url-retrieve-synchronously url)
+ (url-retrieve-synchronously url nil nil mastodon-http--timeout)))))
(defun mastodon-http--get (url)
"Make GET request to URL.
@@ -96,7 +101,9 @@ Pass response buffer to CALLBACK function."
(url-request-extra-headers
`(("Authorization" . ,(concat "Bearer "
(mastodon-auth--access-token))))))
- (url-retrieve-synchronously url)))
+ (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4)
+ (url-retrieve-synchronously url)
+ (url-retrieve-synchronously url nil nil mastodon-http--timeout))))
(defun mastodon-http--get-json (url)
"Make GET request to URL. Return JSON response vector."