branch: externals/plz-media-type commit c76fa0122bad2ccbc1d58c3a05d6bde725c7d020 Author: Roman Scherer <ro...@burningswell.com> Commit: r0man <ro...@burningswell.com>
Move plz-curl-default-args from letrec to let This fixes a regession introduced in: https://github.com/r0man/plz-media-type/commit/9f5a4cbbebc9779ee2cfd3e58c53a30ff79d74e2 The letrec caused previously bound values in plz-curl-default-args to not get passed to the plz function. This fixes the issue. --- plz-media-type.el | 92 ++++++++++++++++++++++---------------------- tests/test-plz-media-type.el | 12 ++++++ 2 files changed, 58 insertions(+), 46 deletions(-) diff --git a/plz-media-type.el b/plz-media-type.el index fb9aae0e1b..4b86ef46a3 100644 --- a/plz-media-type.el +++ b/plz-media-type.el @@ -720,52 +720,52 @@ not. (if-let (media-types (pcase as (`(media-types ,media-types) media-types))) - (condition-case error - (letrec ((plz-curl-default-args (cons "--no-buffer" plz-curl-default-args)) - (result (plz method url - :as 'buffer - :body body - :body-type body-type - :connect-timeout connect-timeout - :decode decode - :else (lambda (error) - (when (or (functionp else) (symbolp else)) - (funcall else (plz-media-type-else - plz-media-type--current - error)))) - :finally (lambda () - (unwind-protect - (when (functionp finally) - (funcall finally)) - (when (buffer-live-p buffer) - (kill-buffer buffer)))) - :headers headers - :noquery noquery - :filter (lambda (process chunk) - (plz-media-type-process-filter process media-types chunk)) - :timeout timeout - :then (if (symbolp then) - then - (lambda (_) - (let ((response (plz-media-type-then plz-media-type--current plz-media-type--response)) - (content (string-trim (buffer-substring (point) (point-max))))) - (if (zerop (length content)) - (when (and (or (functionp then) (symbolp then))) - (funcall then response)) - (when (functionp else) - (setf (plz-response-body response) content) - (funcall else (make-plz-error - :message (format "Failed to parse response, %s byte%s unprocessed" - (length content) (if (= 1 (length content)) "" "s")) - :response response))))))))) - (buffer (if (processp result) (process-buffer result) result))) - (cond ((bufferp result) - (plz-media-type--handle-sync-response result)) - ((processp result) - result) - (t (user-error "Unexpected response: %s" result)))) - ;; TODO: How to kill the buffer for sync requests that raise an error? - (plz-error (plz-media-type--handle-sync-error error media-types))) + (let ((plz-curl-default-args (cons "--no-buffer" plz-curl-default-args))) + (condition-case error + (letrec ((result (plz method url + :as 'buffer + :body body + :body-type body-type + :connect-timeout connect-timeout + :decode decode + :else (lambda (error) + (when (or (functionp else) (symbolp else)) + (funcall else (plz-media-type-else + plz-media-type--current + error)))) + :finally (lambda () + (unwind-protect + (when (functionp finally) + (funcall finally)) + (when (buffer-live-p buffer) + (kill-buffer buffer)))) + :headers headers + :noquery noquery + :filter (lambda (process chunk) + (plz-media-type-process-filter process media-types chunk)) + :timeout timeout + :then (if (symbolp then) + then + (lambda (_) + (let ((response (plz-media-type-then plz-media-type--current plz-media-type--response)) + (content (string-trim (buffer-substring (point) (point-max))))) + (if (zerop (length content)) + (when (and (or (functionp then) (symbolp then))) + (funcall then response)) + (when (functionp else) + (setf (plz-response-body response) content) + (funcall else (make-plz-error + :message (format "Failed to parse response, %s byte%s unprocessed" + (length content) (if (= 1 (length content)) "" "s")) + :response response))))))))) + (buffer (if (processp result) (process-buffer result) result))) + (cond ((bufferp result) + (plz-media-type--handle-sync-response result)) + ((processp result) + result) + (t (user-error "Unexpected response: %s" result)))) + ;; TODO: How to kill the buffer for sync requests that raise an error? + (plz-error (plz-media-type--handle-sync-error error media-types)))) (apply #'plz (append (list method url) rest)))) diff --git a/tests/test-plz-media-type.el b/tests/test-plz-media-type.el index 231112dbf5..0d506a832e 100644 --- a/tests/test-plz-media-type.el +++ b/tests/test-plz-media-type.el @@ -581,6 +581,18 @@ (should (equal '(6 . "Couldn't resolve host. The given remote host was not resolved.") (plz-error-curl-error error)))))) +(ert-deftest test-plz-media-type-request-override-plz-curl-default-args () + (let* ((expected (cons "--verbose" plz-curl-default-args)) + (actual nil) + (then (lambda (_) + (setq actual plz-curl-default-args)))) + (let ((plz-curl-default-args expected) + (process (plz-media-type-request 'get "https://httpbin.org/status/200" + :as `(media-types ,plz-media-types) + :then then))) + (plz-media-type-test-wait process) + (should (equal expected actual))))) + ;;;; Footer (provide 'test-plz-media-type)