branch: elpa/fedi
commit 1e2a8016de0c99b1c50c5f5942a1190d980cfbba
Author: marty hiatt <[email protected]>
Commit: marty hiatt <[email protected]>
http: add fedi-http--basic-auth-request
---
fedi-http.el | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/fedi-http.el b/fedi-http.el
index 6dc6f167647..6406c8344c7 100644
--- a/fedi-http.el
+++ b/fedi-http.el
@@ -371,6 +371,22 @@ Then run function CALLBACK with arguements CBARGS."
(with-temp-buffer
(url-retrieve url callback cbargs))))
+;;; BASIC AUTH REQUEST
+
+(defun fedi-http--basic-auth-request (req-fun url user
+ &optional pwd &rest args)
+ "Do a BasicAuth request.
+Call REQ-FUN, a request function, on URL, providing USER and PASSWORD.
+ARGS is any addition arguments for REQ-FUN, after the URL.
+REQ-FUN can be a fedi.el request function such as `fedi-http--post'."
+ (let* ((pwd (or pwd (read-passwd (format "Password: "))))
+ (auth (base64-encode-string
+ (format "%s:%s" user pwd)))
+ (url-request-extra-headers
+ (list (cons "Authorization"
+ (format "Basic %s" auth)))))
+ (apply req-fun url args)))
+
;; ;; TODO: test for curl first?
;; (defun fedi-http--post-media-attachment (url filename caption)
;; "Make POST request to upload FILENAME with CAPTION to the server's media
URL.