From 605c2329076daf892d50c1407359655e5ca4c23d Mon Sep 17 00:00:00 2001 From: Ian Eure Date: Sun, 3 May 2020 11:01:01 -0700 Subject: Set a HTTP timeout. This prevents mastodon.el from locking Emacs and spinning forever. --- lisp/mastodon-http.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-http.el') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 7be4467..c255c81 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.") + (defun mastodon-http--api (endpoint) "Return Mastondon API URL for ENDPOINT." (concat mastodon-instance-url "/api/" @@ -86,7 +89,7 @@ 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)))) + (url-retrieve-synchronously url nil nil mastodon-http--timeout)))) (defun mastodon-http--get (url) "Make GET request to URL. @@ -96,7 +99,7 @@ Pass response buffer to CALLBACK function." (url-request-extra-headers `(("Authorization" . ,(concat "Bearer " (mastodon-auth--access-token)))))) - (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." -- cgit v1.2.3 From 34d3b220fedd62b00b605cdc773f66de21c2b53f Mon Sep 17 00:00:00 2001 From: Ian Eure Date: Sun, 3 May 2020 11:51:00 -0700 Subject: Guard against the old version of Emacs which mastodon.el supports. --- lisp/mastodon-http.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-http.el') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index c255c81..04a2235 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -36,7 +36,7 @@ (defvar mastodon-http--api-version "v1") (defconst mastodon-http--timeout 5 - "HTTP request timeout, in seconds.") + "HTTP request timeout, in seconds. Has no effect on Emacs < 26.1.") (defun mastodon-http--api (endpoint) "Return Mastondon API URL for ENDPOINT." @@ -89,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 nil nil mastodon-http--timeout)))) + (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. @@ -99,7 +101,9 @@ Pass response buffer to CALLBACK function." (url-request-extra-headers `(("Authorization" . ,(concat "Bearer " (mastodon-auth--access-token)))))) - (url-retrieve-synchronously url nil nil mastodon-http--timeout))) + (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." -- cgit v1.2.3