diff options
author | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2023-10-02 15:47:41 +0200 |
---|---|---|
committer | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2023-10-02 15:47:41 +0200 |
commit | cada9d84d13e0df5eeafa97f00e34c56a46473b8 (patch) | |
tree | d755de0283f5b50beade300a631f5dcad3524993 /lisp | |
parent | a440c4c13460df0188b1863d86bcaeeca8d5f0b2 (diff) |
port fedi-http handling of POST JSON data or not
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-http.el | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index ab621a2..cb4c323 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -127,17 +127,20 @@ Used for API form data parameters that take an array." (cl-loop for x in array collect (cons param-str x))) -(defun mastodon-http--post (url &optional params headers unauthenticated-p) +(defun mastodon-http--post (url &optional params headers unauthenticated-p json) "POST synchronously to URL, optionally with PARAMS and HEADERS. Authorization header is included by default unless UNAUTHENTICATED-P is non-nil." (mastodon-http--authorized-request "POST" - (let ((url-request-data (when params - (mastodon-http--build-params-string params))) - (url-request-extra-headers - (append url-request-extra-headers ; auth set in macro - (unless (assoc "Content-Type" headers) ; pleroma compat: - '(("Content-Type" . "application/x-www-form-urlencoded"))) - headers))) + (let* ((url-request-data + (when params + (if json + (json-encode params) + (fedi-http--build-params-string params)))) + (url-request-extra-headers + (append url-request-extra-headers ; auth set in macro + (unless (assoc "Content-Type" headers) ; pleroma compat: + '(("Content-Type" . "application/x-www-form-urlencoded"))) + headers))) (with-temp-buffer (mastodon-http--url-retrieve-synchronously url))) unauthenticated-p)) |