From db078f72b7d176f18e24792e93319322b02795bb Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 1 Oct 2024 22:20:45 +0200 Subject: rewrite http--patch (+ json confusion) --- lisp/mastodon-http.el | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-http.el') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index fbae8a7..546d5bd 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -298,11 +298,26 @@ Optionally specify the PARAMS to send." (with-current-buffer (mastodon-http--patch url params) (mastodon-http--process-json))) -(defun mastodon-http--patch (base-url &optional params) - "Make synchronous PATCH request to BASE-URL. +(defun mastodon-http--patch (url &optional params json) + "Make synchronous PATCH request to URL. Optionally specify the PARAMS to send." (mastodon-http--authorized-request "PATCH" - (let ((url (mastodon-http--concat-params-to-url base-url params))) + ;; NB: unlike POST, PATCHing only works if we use query params! + ;; so here, unless JSON arg, we use query params and do not set + ;; `url-request-data'. this is probably an error, i don't understand it. + (let* ((url-request-data + (when (and params json) + (encode-coding-string + (json-encode params) 'utf-8))) + ;; (mastodon-http--build-params-string params)))) + (url (unless json + (mastodon-http--concat-params-to-url url params))) + (headers (when json + '(("Content-Type" . "application/json") + ("Accept" . "application/json")))) + (url-request-extra-headers + (append url-request-extra-headers headers))) + (message "Data: %s" url-request-data) (mastodon-http--url-retrieve-synchronously url)))) ;; Asynchronous functions -- cgit v1.2.3