aboutsummaryrefslogtreecommitdiff
path: root/buildbot-utils.el
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2023-07-12 00:49:10 +1000
committerYuchen Pei <id@ypei.org>2023-07-12 00:49:10 +1000
commit3774f49e0a566359193d98e716fa14341ee37b08 (patch)
treeaaf1b0b308d8ba187638ec3351be5cde0e9ba258 /buildbot-utils.el
parent071ba8408abf2d13c914a331c719779d7696d1dd (diff)
Addressing review comments from Prot.
Diffstat (limited to 'buildbot-utils.el')
-rw-r--r--buildbot-utils.el44
1 files changed, 16 insertions, 28 deletions
diff --git a/buildbot-utils.el b/buildbot-utils.el
index 17dc085..d016330 100644
--- a/buildbot-utils.el
+++ b/buildbot-utils.el
@@ -47,9 +47,12 @@
(kill-region (point) (progn (re-search-forward "\r?\n\r?\n")
(point)))))
-(defun buildbot-url-fetch-json (url &optional decompression with-header)
- "Fetch and parse a json object from URL.
+(defun buildbot-url-fetch-internal (url processor &optional
+ decompression with-header)
+ "Fetch from URL and process the response payload using PROCESSOR.
+PROCESSOR is a function that takes no argument and processes the
+current buffer.
With non-nil DECOMPRESSION, decompress the response.
With non-nil WITH-HEADER, include the header in the result."
(with-current-buffer (get-buffer-create buildbot-client-buffer-name)
@@ -73,39 +76,24 @@ With non-nil WITH-HEADER, include the header in the result."
(if with-header
(list
(cons 'header fields)
- (cons 'json (json-read)))
- (json-read)))
+ (cons 'json (funcall processor)))
+ (funcall processor)))
(error "HTTP error: %s" (buffer-substring (point) (point-max)))))))
+(defun buildbot-url-fetch-json (url &optional decompression with-header)
+ "Fetch and parse a json object from URL.
+
+With non-nil DECOMPRESSION, decompress the response.
+With non-nil WITH-HEADER, include the header in the result."
+ (buildbot-url-fetch-internal url 'json-read decompression with-header))
+
(defun buildbot-url-fetch-raw (url &optional decompression with-header)
"Fetch from URL.
With non-nil DECOMPRESSION, decompress the response.
With non-nil WITH-HEADER, include the header in the result."
- (with-current-buffer (get-buffer-create buildbot-client-buffer-name)
- (goto-char (point-max))
- (insert "[" (current-time-string) "] Request: " url "\n"))
- (with-current-buffer (url-retrieve-synchronously url t)
- (let ((header) (status) (fields))
- (buildbot-delete-http-header)
- (goto-char (point-min))
- (setq header (buildbot-parse-http-header (car kill-ring))
- status (alist-get 'status header)
- fields (alist-get 'fields header))
- (with-current-buffer buildbot-client-buffer-name
- (insert "[" (current-time-string) "] Response: " status "\n"))
- (when decompression
- (call-process-region (point) (point-max) "gunzip" t t t)
- (goto-char (point-min)))
- (call-interactively 'delete-trailing-whitespace)
- (if (string= status "200")
- (unless (= (point) (point-max))
- (if with-header
- (list
- (cons 'header fields)
- (cons 'json (buffer-string)))
- (buffer-string)))
- (error "HTTP error: %s" (buffer-substring (point) (point-max)))))))
+ (buildbot-url-fetch-internal url 'buffer-string decompression
+ with-header))
(defun buildbot-format-attr (attr)
"Format an alist ATTR into a url query string."