branch: elpa/fedi
commit 2fc17857ff8529250390153ea6b24089a1eb1a80
Author: marty hiatt <[email protected]>
Commit: marty hiatt <[email protected]>
http: use built-in url.el response status function.
---
fedi-http.el | 24 ++++--------------------
1 file changed, 4 insertions(+), 20 deletions(-)
diff --git a/fedi-http.el b/fedi-http.el
index 9bbaedbc0b1..5e0d6ef1c0d 100644
--- a/fedi-http.el
+++ b/fedi-http.el
@@ -79,23 +79,6 @@ A random one is picked at package initialization.")
(or ver-str fedi-http--api-version)
"/" endpoint))
-(defun fedi-http--response ()
- "Capture response buffer content as string."
- (with-current-buffer (current-buffer)
- (buffer-substring-no-properties (point-min) (point-max))))
-
-(defun fedi-http--response-body (pattern)
- "Return substring matching PATTERN from `fedi-http--response'."
- (let ((resp (fedi-http--response)))
- (string-match pattern resp)
- (match-string 0 resp)))
-
-(defun fedi-http--status ()
- "Return HTTP Response Status Code from `fedi-http--response'."
- (let* ((status-line (fedi-http--response-body "^HTTP/1.*$")))
- (string-match "[0-9][0-9][0-9]" status-line)
- (match-string 0 status-line)))
-
(defun fedi-http--render-html-err (string)
"Render STRING as HTML in a temp buffer.
STRING should be HTML for a 404 errror."
@@ -257,12 +240,13 @@ Optionally, provide an ERROR-FUN, called on the process
JSON response,
to returnany error message needed."
(let ((status (condition-case _err
(with-current-buffer response
- (fedi-http--status))
+ (url-http-parse-response))
(wrong-type-argument
"Looks like we got no response from the server."))))
- (cond ((string-prefix-p "2" status)
+ (cond ((and (>= status 200)
+ (<= status 299))
(funcall success response))
- ((string-prefix-p "404" status)
+ ((= 404 status)
(message "Error %s: page not found" status))
(t
(let ((json-response (with-current-buffer response