emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/plz-media-type a9236fa862 1/3: Add support for debuggin


From: ELPA Syncer
Subject: [elpa] externals/plz-media-type a9236fa862 1/3: Add support for debugging HTTP responses
Date: Mon, 4 Nov 2024 15:58:49 -0500 (EST)

branch: externals/plz-media-type
commit a9236fa8628ed7ae3070a78a9883bc049c912859
Author: Roman Scherer <roman@burningswell.com>
Commit: r0man <roman@burningswell.com>

    Add support for debugging HTTP responses
---
 plz-media-type.el  | 29 +++++++++++++++++++++++++++++
 plz-media-type.org | 15 +++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/plz-media-type.el b/plz-media-type.el
index c5aee2f7a0..aa9504a261 100644
--- a/plz-media-type.el
+++ b/plz-media-type.el
@@ -44,6 +44,29 @@
 (require 'eieio)
 (require 'plz)
 
+(defcustom plz-media-type-debug-response-buffer "*plz-media-type-response*"
+  "The name of the buffer to which the HTTP response is written to.
+
+When `plz-media-type-debug-p' is non-nil, the HTTP response will
+be written to this buffer.  The buffer will be erased on each
+HTTP request, unless configured otherwise with
+`plz-media-type-debug-erase-buffer-p'."
+  :group 'plz-media-type
+  :safe #'stringp
+  :type 'string)
+
+(defcustom plz-media-type-debug-erase-buffer-p t
+  "Whether to erase the response buffer on each new request or not."
+  :group 'plz-media-type
+  :safe #'booleanp
+  :type 'boolean)
+
+(defcustom plz-media-type-debug-p nil
+  "Whether to write the HTTP response to the debug buffer or not."
+  :group 'plz-media-type
+  :safe #'booleanp
+  :type 'boolean)
+
 (defclass plz-media-type ()
   ((coding-system
     :documentation "The coding system to use for the media type."
@@ -221,6 +244,9 @@ MEDIA-TYPES is an association list from media type to an
 instance of a content type class.
 
 STRING which is output just received from the process."
+  (when plz-media-type-debug-p
+    (with-current-buffer (get-buffer-create 
plz-media-type-debug-response-buffer)
+      (insert string)))
   (when (buffer-live-p (process-buffer process))
     (with-current-buffer (process-buffer process)
       (let ((moving (= (point) (process-mark process))))
@@ -677,6 +703,9 @@ not.
                          (`(media-types ,media-types)
                           media-types)))
       (let ((buffer))
+        (when (and plz-media-type-debug-p plz-media-type-debug-erase-buffer-p)
+          (with-current-buffer (get-buffer-create 
plz-media-type-debug-response-buffer)
+            (erase-buffer)))
         (condition-case error
             (let* ((plz-curl-default-args (cons "--no-buffer" 
plz-curl-default-args))
                    (result (plz method url
diff --git a/plz-media-type.org b/plz-media-type.org
index 97ce27e76c..448ebbc574 100644
--- a/plz-media-type.org
+++ b/plz-media-type.org
@@ -28,6 +28,8 @@ media type formats.
 - [[#usage][Usage]]
   - [[#quick-start][Quick Start]]
   - [[#media-types][Media Types]]
+- [[#troubleshooting][Troubleshooting]]
+  - [[#debugging-http-responses][Debugging HTTP responses]]
 - [[#credits][Credits]]
 - [[#copyright-assignment][Copyright assignment]]
 :END:
@@ -333,6 +335,19 @@ does not parse the response body in any way.
                 "{\n  \"slideshow\": {\n    \"author\": \"Yours Truly\", \n    
\"date\": \"date of publication\", \n    \"slides\": [\n      {\n        
\"title\": \"Wake up to WonderWidgets!\", \n        \"type\": \"all\"\n      }, 
\n      {\n        \"items\": [\n          \"Why <em>WonderWidgets</em> are 
great\", \n          \"Who <em>buys</em> WonderWidgets\"\n        ], \n        
\"title\": \"Overview\", \n        \"type\": \"all\"\n      }\n    ], \n    
\"title\": \"Sample Slide Sho [...]
 #+end_src
 
+* Troubleshooting
+
+** Debugging HTTP responses
+
+It might be useful to see the full HTTP response while developing a
+new media type format or ~plz-media-type~ is failing to parse a
+response of an HTTP request. When the ~plz-media-type-debug-p~ custom
+variable is set to a non-nil value, each chunk of the HTTP response is
+written to the buffer configured by the
+~plz-media-type-debug-response-buffer~ custom variable as it
+arrives. The buffer is cleared on each new request, unless
+~plz-media-type-debug-erase-buffer-p~ is set to a non-nil value.
+
 * Credits
 
 - Thanks to [[https://github.com/ahyatt][ahyatt]] and 
[[https://github.com/alphapapa][alphapapa]] for their help and advice.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]