branch: elpa/hyperdrive
commit 28d296022252bf6ab7fdaf8e5a845e0f556c5f4a
Author: Joseph Turner <[email protected]>
Commit: Joseph Turner <[email protected]>
Change: (he/api) Always use :body-type 'binary
:body-type 'binary causes plz to pass the PUT request body to curl
with --data-binary as opposed to --data. With --data, curl strips
carriage returns and newlines from body content, but with
--data-binary, body content is left as-is.
This commit does not change any behavior since all PUT requests either
already used :body-type 'binary or they had :body `(file FILENAME).
---
hyperdrive-dir.el | 2 +-
hyperdrive-lib.el | 12 +++++++-----
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/hyperdrive-dir.el b/hyperdrive-dir.el
index a023674bb2..f11458e722 100644
--- a/hyperdrive-dir.el
+++ b/hyperdrive-dir.el
@@ -390,7 +390,7 @@ see Info node `(elisp)Yanking Media'."
(h//entry-directory-p h/current-entry)))
(let ((entry (h/read-entry (h//context-hyperdrive :predicate #'h/writablep)
:latest-version t)))
- (he/api 'put entry :body image :body-type 'binary
+ (he/api 'put entry :body image
;; TODO: Pass MIME type in a header? hyper-gateway detects it for us.
:then (lambda (_res) (h/open entry))
:else (lambda (plz-error)
diff --git a/hyperdrive-lib.el b/hyperdrive-lib.el
index d811f9492c..d57da517e7 100644
--- a/hyperdrive-lib.el
+++ b/hyperdrive-lib.el
@@ -210,13 +210,17 @@ to the gateway which do not involve an entry. Otherwise,
use
(defun he/api (method entry &rest rest)
"Make hyperdrive API request by METHOD for ENTRY.
REST is passed to `hyperdrive-api', which see. AS keyword should
-be nil, because it is always set to `response'. Automatically
-calls `hyperdrive-entry--api-then' to update metadata from the
-response."
+be nil, because it is always set to `response'. BODY-TYPE
+keyword should be nil, because it is always set to `binary'.
+Automatically calls `hyperdrive-entry--api-then' to update
+metadata from the response."
(declare (indent defun))
;; Always use :as 'response
(cl-assert (null (plist-get rest :as)))
(setf (plist-get rest :as) 'response)
+ ;; Always use :body-type 'binary so curl leaves carriage returns and
newlines.
+ (cl-assert (null (plist-get rest :body-type)))
+ (setf (plist-get rest :body-type) 'binary)
(unless (map-elt rest :then) (setf (map-elt rest :then) 'sync))
(pcase-let* (((map :then) rest))
(unless (eq 'sync then)
@@ -1020,8 +1024,6 @@ Call ELSE if request fails."
THEN and ELSE are passed to `hyperdrive-entry-api', which see."
(declare (indent defun))
(he/api 'put entry
- ;; TODO: Investigate whether we should use 'text body type for text
buffers.
- :body-type 'binary
;; TODO: plz accepts buffer as a body, we should refactor calls to h/write
;; to pass in a buffer instead of a buffer-string.
:body body :then then :else else :queue queue))