[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/plz 9f83a74eef 2/2: Fix: For ":as 'buffer" result type
From: |
ELPA Syncer |
Subject: |
[elpa] externals/plz 9f83a74eef 2/2: Fix: For ":as 'buffer" result type |
Date: |
Thu, 29 Jun 2023 06:59:21 -0400 (EDT) |
branch: externals/plz
commit 9f83a74eef0d19df3753d73af736eceac206c61b
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Fix: For ":as 'buffer" result type
---
README.org | 1 +
plz.el | 18 ++++++++++++++----
plz.info | 33 ++++++++++++++++++---------------
tests/test-plz.el | 20 ++++++++++++--------
4 files changed, 45 insertions(+), 27 deletions(-)
diff --git a/README.org b/README.org
index 8c8977fa3d..5fdb77744b 100644
--- a/README.org
+++ b/README.org
@@ -188,6 +188,7 @@ You may also clear a queue with ~plz-clear~, which cancels
any active or queued
+ Significant improvement in reliability by implementing failsafes and
workarounds for Emacs's process-handling code. (See
[[https://github.com/alphapapa/plz.el/issues/3][#3]].)
+ STDERR output from curl processes is not included in response bodies (which
sometimes happened, depending on Emacs's internal race conditions). (Fixes
[[https://github.com/alphapapa/plz.el/issues/23][#23]].)
+ Use ~with-local-quit~ for synchronous requests (preventing Emacs from
complaining sometimes). (Fixes
[[https://github.com/alphapapa/plz.el/issues/26][#26]].)
++ Various fixes for ~:as 'buffer~ result type: decode body when appropriate;
unset multibyte for binary; narrow to body; don't kill buffer prematurely.
*Internal*
+ Response processing now happens outside the process sentinel, so any errors
(e.g. in user callbacks) are not signaled from inside the sentinel. (This
avoids the 2-second pause Emacs imposes in such cases.)
diff --git a/plz.el b/plz.el
index 9c5e2e91ce..1cc8f749a9 100644
--- a/plz.el
+++ b/plz.el
@@ -275,7 +275,8 @@ AS selects the kind of result to pass to the callback
function
THEN, or the kind of result to return for synchronous requests.
It may be:
-- `buffer' to pass the response buffer.
+- `buffer' to pass the response buffer, which will be narrowed to
+ the response body and decoded according to DECODE.
- `binary' to pass the response body as an un-decoded string.
@@ -426,8 +427,16 @@ NOQUERY is passed to `make-process', which see.
(decode-coding-region (point) (point-max) coding-system))
(funcall then (or (buffer-string)
(make-plz-error :message (format "buffer-string
is nil in buffer:%S" process-buffer)))))))
- ('buffer (lambda ()
- (funcall then (current-buffer))))
+ ('buffer (progn
+ (setf (process-get process :plz-as) 'buffer)
+ (lambda ()
+ (let ((coding-system (or (plz--coding-system) 'utf-8)))
+ (pcase as
+ ('binary (set-buffer-multibyte nil)))
+ (plz--narrow-to-body)
+ (when decode
+ (decode-coding-region (point) (point-max)
coding-system)))
+ (funcall then (current-buffer)))))
('response (lambda ()
(funcall then (or (plz--response :decode-p decode)
(make-plz-error :message (format
"response is nil for buffer:%S buffer-string:%S"
@@ -781,7 +790,8 @@ argument passed to `plz--sentinel', which see."
((and (pred functionp) fn) (funcall fn err)))))))
(when-let ((finally (process-get process :plz-finally)))
(funcall finally))
- (unless (process-get process :plz-sync)
+ (unless (or (process-get process :plz-sync)
+ (eq 'buffer (process-get process :plz-as)))
(kill-buffer buffer))))
(defun plz--stderr-sentinel (process status)
diff --git a/plz.info b/plz.info
index 057c64a43a..872e53c5a2 100644
--- a/plz.info
+++ b/plz.info
@@ -322,6 +322,9 @@ File: README.info, Node: 07-pre, Next: 06, Up: Changelog
• Use ‘with-local-quit’ for synchronous requests (preventing Emacs
from complaining sometimes). (Fixes #26
(https://github.com/alphapapa/plz.el/issues/26).)
+ • Various fixes for ‘:as 'buffer’ result type: decode body when
+ appropriate; unset multibyte for binary; narrow to body; don’t kill
+ buffer prematurely.
*Internal*
• Response processing now happens outside the process sentinel, so
@@ -537,21 +540,21 @@ Node: Queueing6859
Node: Tips8242
Node: Changelog8543
Node: 07-pre8812
-Node: 0610457
-Node: 05411072
-Node: 05311315
-Node: 05211631
-Node: 05111838
-Node: 0512090
-Node: 0412296
-Node: 0313202
-Node: 02113650
-Node: 0213801
-Node: 0113932
-Node: Credits14028
-Node: Development14394
-Node: Copyright assignment14908
-Node: License15496
+Node: 0610630
+Node: 05411245
+Node: 05311488
+Node: 05211804
+Node: 05112011
+Node: 0512263
+Node: 0412469
+Node: 0313375
+Node: 02113823
+Node: 0213974
+Node: 0114105
+Node: Credits14201
+Node: Development14567
+Node: Copyright assignment15081
+Node: License15669
End Tag Table
diff --git a/tests/test-plz.el b/tests/test-plz.el
index f3b8207a38..3f5f0a85f1 100644
--- a/tests/test-plz.el
+++ b/tests/test-plz.el
@@ -176,15 +176,19 @@ Also, any instance of \"URI-PREFIX\" in URL-PART is
replaced with
(should (string-match "curl" test-string))))
(plz-deftest plz-get-buffer nil
- ;; The sentinel kills the buffer, so we get the buffer as a string.
- (let* ((test-buffer-string)
+ (let* ((result-buffer)
(process (plz 'get (plz-test-url "/get")
- :as 'buffer
- :then (lambda (buffer)
- (with-current-buffer buffer
- (setf test-buffer-string (buffer-string)))))))
- (plz-test-wait process)
- (should (string-match "curl" test-buffer-string))))
+ :as 'buffer :then (lambda (buffer)
+ (setf result-buffer buffer)))))
+ (unwind-protect
+ (progn
+ (plz-test-wait process)
+ (should (buffer-live-p result-buffer))
+ (with-current-buffer result-buffer
+ (should-not (looking-at-p plz-http-response-status-line-regexp))
+ (should (string-match "curl" (buffer-string)))))
+ (kill-buffer result-buffer)
+ (should-not (buffer-live-p result-buffer)))))
(plz-deftest plz-get-response nil
(let* ((test-response)