[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/plz 2d20ca5030 02/81: Changes
From: |
ELPA Syncer |
Subject: |
[elpa] externals/plz 2d20ca5030 02/81: Changes |
Date: |
Wed, 11 May 2022 17:57:57 -0400 (EDT) |
branch: externals/plz
commit 2d20ca5030c5a4df30e7bd8a3a76584276c532bf
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Changes
---
http-lib.el | 72 +++++++++++++++++++++++++++++++++++----------------
test/test-http-lib.el | 6 ++---
2 files changed, 52 insertions(+), 26 deletions(-)
diff --git a/http-lib.el b/http-lib.el
index 7903dcbb33..b81e399eff 100644
--- a/http-lib.el
+++ b/http-lib.el
@@ -155,41 +155,69 @@
;;;; Functions
-(cl-defun http-lib-get (url &key headers _connect-timeout
+(cl-defun http-lib-get (url &key headers _connect-timeout sync
success error)
"FIXME: Docstring."
- (http-lib-request 'get url
- :headers headers
- ;; :connect-timeout timeout
- :success success
- :error error))
-
-(cl-defun http-lib-request (_method url &key headers _connect-timeout
- success error)
+ (http-lib--request 'get url
+ :sync sync
+ :headers headers
+ ;; :connect-timeout timeout
+ :success success
+ :error error))
+
+(cl-defun http-lib-request-async (&rest args)
+ "FIXME: Docstring."
+ (apply #'http-lib--request args))
+
+(cl-defun http-lib-request-sync (&rest args)
+ "FIXME: Docstring."
+ (apply #'http-lib--request :sync t args))
+
+(cl-defun http-lib--request (_method url &key headers _connect-timeout sync
+ success error)
"FIXME: Docstring."
;; Inspired by and copied from `elfeed-curl-retrieve'.
+ (let* ((coding-system-for-read 'binary)
+ (process-connection-type nil)
+ (header-args (cl-loop for (key . value) in headers
+ collect (format "--header %s: %s" key value)))
+ (curl-args (append http-lib-curl-default-args header-args
+ (list url))))
+ (if sync
+ (http-lib-request--sync curl-args :success success :error error)
+ (http-lib-request--async curl-args :success success :error error))))
+
+(cl-defun http-lib-request--async (curl-args &key success error)
+ "FIXME: Docstring."
(with-current-buffer (generate-new-buffer "*http-lib-request-curl*")
- (let* ((coding-system-for-read 'binary)
- (process-connection-type nil)
- (header-args (cl-loop for (key . value) in headers
- collect (format "--header %s: %s" key value)))
- (curl-args (append http-lib-curl-default-args header-args
- (list url)))
- (process (apply #'start-process "http-lib-request-curl"
(current-buffer)
- http-lib-curl-program curl-args)))
+ (let ((process (make-process :name "http-lib-request-curl"
+ :buffer (current-buffer)
+ :command (append (list http-lib-curl-program)
curl-args)
+ :connection-type 'pipe
+ :sentinel #'http-lib--sentinel
+ :stderr (current-buffer))))
(setf http-lib-success success
- http-lib-error error
- (process-sentinel process) #'http-lib--sentinel)
+ http-lib-error error)
process)))
-(defun http-lib--sentinel (process status)
+(cl-defun http-lib-request--sync (curl-args &key success error)
+ "FIXME: Docstring."
+ (with-current-buffer (generate-new-buffer "*http-lib-request-curl*")
+ (let ((status (apply #'call-process http-lib-curl-program nil t nil
+ curl-args))
+ (http-lib-success #'identity))
+ (http-lib--sentinel (current-buffer) status))))
+
+(defun http-lib--sentinel (process-or-buffer status)
"FIXME: Docstring."
;; Inspired by and some code copied from `elfeed-curl--sentinel'.
- (let ((buffer (process-buffer process)))
+ (let ((buffer (cl-etypecase process-or-buffer
+ (process (process-buffer process-or-buffer))
+ (buffer process-or-buffer))))
(unwind-protect
(with-current-buffer buffer
(pcase status
- ("finished\n"
+ ((or 0 "finished\n")
;; Request completed successfully: call success callback with
parsed response.
(let ((response (http-lib--parse-response buffer)))
(funcall http-lib-success response)))
diff --git a/test/test-http-lib.el b/test/test-http-lib.el
index 9ad0582bd1..d8d780df02 100644
--- a/test/test-http-lib.el
+++ b/test/test-http-lib.el
@@ -41,10 +41,8 @@
;;;; Tests
-(ert-deftest http-lib-get nil
- (http-lib-response-body (http-lib-get "https://httpbin.org/get"))
- )
-
+(ert-deftest http-lib-get-sync nil
+ (http-lib-response-p (http-lib-get "https://httpbin.org/get" :sync t)))
;;;; Footer
- [elpa] branch externals/plz created (now 9156de9c59), ELPA Syncer, 2022/05/11
- [elpa] externals/plz e7d9513bb9 03/81: Rename, ELPA Syncer, 2022/05/11
- [elpa] externals/plz c7c16e2123 04/81: Changes, ELPA Syncer, 2022/05/11
- [elpa] externals/plz debfc864c8 08/81: Changes, ELPA Syncer, 2022/05/11
- [elpa] externals/plz f0a0d114a6 01/81: Initial commit, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 2d20ca5030 02/81: Changes,
ELPA Syncer <=
- [elpa] externals/plz 5f54b5ebec 06/81: Changes, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 1016279174 07/81: Changes, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 897c5bbfb2 13/81: Improvements, error handling, ELPA Syncer, 2022/05/11
- [elpa] externals/plz e14ea7327d 14/81: Tidying, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 2b7944e0f9 05/81: Changes, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 950a5498cb 16/81: Tidy, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 44e6f02064 17/81: Binary content, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 5bd683ead8 19/81: Tidy tests, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 3249835c8b 18/81: Tidy tests, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 21a7318f1c 26/81: Tests: Tidy/rename, ELPA Syncer, 2022/05/11