[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/url-scgi 3686dad2bd 04/48: Cleanups in url-scgi.el
From: |
ELPA Syncer |
Subject: |
[elpa] externals/url-scgi 3686dad2bd 04/48: Cleanups in url-scgi.el |
Date: |
Fri, 28 Oct 2022 22:58:28 -0400 (EDT) |
branch: externals/url-scgi
commit 3686dad2bdb72a619381dd1349174c9889b45e31
Author: Stefan Kangas <skangas@skangas.se>
Commit: Stefan Kangas <skangas@skangas.se>
Cleanups in url-scgi.el
---
url-scgi.el | 79 +++++++++++++++++++------------------------------------------
1 file changed, 24 insertions(+), 55 deletions(-)
diff --git a/url-scgi.el b/url-scgi.el
index 27c2e00f7b..09dc501d09 100644
--- a/url-scgi.el
+++ b/url-scgi.el
@@ -37,33 +37,26 @@
(eval-when-compile (require 'cl))
-(defvar url-scgi-content-length)
-(defvar url-scgi-content-type)
(defvar url-scgi-connection-opened)
-
(defconst url-scgi-asynchronous-p t "SCGI retrievals are asynchronous.")
(defun scgi-string-to-netstring (str)
- "Converts a string into a netstring as defined by the SCGI
-specification."
- (let ((len (length str)))
- (concat (number-to-string len)
- ":" str ",")))
+ "Converts a string into a SCGI protocol netstring."
+ (format "%d:%s," (length str) str))
(defun scgi-add-null-bytes (&rest args)
(apply 'concat (mapcar (lambda (a) (concat a "\000")) args)))
(defun scgi-make-request-header (data)
- (scgi-add-null-bytes "CONTENT_LENGTH"
- (number-to-string (length data))
- "SCGI" "1"))
+ (scgi-string-to-netstring
+ (scgi-add-null-bytes
+ "CONTENT_LENGTH" (number-to-string (length data))
+ "SCGI" "1")))
(defun url-scgi-create-request ()
(declare (special url-request-data))
- (concat
- (scgi-string-to-netstring
- (scgi-make-request-header url-request-data))
- url-request-data))
+ (concat (scgi-make-request-header url-request-data)
+ url-request-data))
(defun url-scgi-activate-callback ()
"Activate callback specified when this buffer was created."
@@ -71,27 +64,8 @@ specification."
url-callback-arguments))
(apply url-callback-function url-callback-arguments))
-(defun url-scgi-parse-headers ()
- (declare (special url-scgi-content-length
- url-scgi-content-type))
- (save-restriction
- (save-match-data
- (mail-narrow-to-head)
- (goto-char (point-min))
- (while (re-search-forward "\r$" nil t)
- (replace-match ""))
- (let ((status (mail-fetch-field "status"))
- (content-length (mail-fetch-field "content-length"))
- (content-type (mail-fetch-field "content-type")))
- (when content-length
- (setq url-scgi-content-length content-length))
- (when content-type
- (setq url-scgi-content-length content-type))
- (when (and status (not (equal status "200 OK")))
- (error (message (concat "Got status response: " status)))))))
- t)
-
(defun url-scgi-get-connection (host port)
+ "Set up a new connection and return it."
(let ((buf (generate-new-buffer " *url-scgi-temp*")))
;; `url-open-stream' needs a buffer in which to do things
;; like authentication. But we use another buffer afterwards.
@@ -114,7 +88,8 @@ specification."
(let* ((host (url-host url))
(port (url-port url))
(connection (url-scgi-get-connection host port))
- (buffer (generate-new-buffer (format " *scgi %s:%d*" host port))))
+ (buffer (generate-new-buffer
+ (format " *scgi %s:%d*" host port))))
(if (not connection)
;; Failed to open the connection for some reason
(progn
@@ -122,13 +97,10 @@ specification."
(setq buffer nil)
(error "Could not create connection to %s:%d" host port))
(with-current-buffer buffer
- (mm-disable-multibyte)
(setq url-current-object url
mode-line-format "%b [%s]")
(dolist (var '(url-scgi-connection-opened
- url-scgi-content-type
- url-scgi-content-length
url-callback-function
url-callback-arguments))
(set (make-local-variable var) nil))
@@ -138,23 +110,26 @@ specification."
url-scgi-connection-opened nil)
(set-process-buffer connection buffer)
- (set-process-filter connection 'url-scgi-filter)
- (set-process-sentinel connection 'url-scgi-async-sentinel)
- (let ((status (process-status connection)))
- (cond ((eq status 'failed)
- (error "Could not create connection to %s:%d" host port))
- ((eq status 'open)
- (process-send-string connection (url-scgi-create-request))
- (setq url-scgi-connection-opened t))))))
+ (pcase (process-status connection)
+ (`connect
+ ;; Asynchronous connection
+ (set-process-sentinel connection 'url-scgi-async-sentinel))
+ (`failed
+ ;; Asynchronous connection failed
+ (error "Could not create connection to %s:%d" host port))
+ (_
+ (setq url-scgi-connection-opened t)
+ (process-send-string connection (url-scgi-create-request))))))
buffer))
(defun url-scgi-async-sentinel (proc why)
+ ;; We are performing an asynchronous connection, and a status change
+ ;; has occurred.
(declare (special url-callback-arguments))
(with-current-buffer (process-buffer proc)
(cond
(url-scgi-connection-opened
- (if (url-scgi-parse-headers)
- (url-scgi-activate-callback)))
+ (url-scgi-activate-callback))
((string= (substring why 0 4) "open")
(setq url-scgi-connection-opened t)
(process-send-string proc (url-scgi-create-request)))
@@ -166,12 +141,6 @@ specification."
(car url-callback-arguments)))
(url-scgi-activate-callback)))))
-(defun url-scgi-filter (proc data)
- (with-current-buffer (process-buffer proc)
- (save-excursion
- (goto-char (point-max))
- (insert data))))
-
(provide 'url-scgi)
;;; url-scgi.el ends here
- [elpa] branch externals/url-scgi created (now ce5e1d5fd1), ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi 2d43fa147c 02/48: Add url-scgi.el: SCGI Uniform Resource Locator retrieval code, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi 103dd508e1 03/48: url-scgi.el: Support Emacs 24, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi 62a6cf9305 07/48: Update documentation and add new doc/ directory, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi 248962b6d6 08/48: url-scgi: Fix scgi socket on absolute path, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi 8f5564a783 10/48: url-scgi: untabify, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi 60154c472f 01/48: Add COPYING file containing the GPLv3., ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi 3686dad2bd 04/48: Cleanups in url-scgi.el,
ELPA Syncer <=
- [elpa] externals/url-scgi f868b8be51 05/48: Support using xmlrpc over a file bound socket, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi 1f76fba6a2 06/48: Use lexical binding, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi efd8de5ec8 09/48: url-scgi: fix compile time warning, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi 44ee68353b 12/48: url-scgi: Add first unit tests, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi 37f3ce8fa6 22/48: Fix some comments and docstrings, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi 66a7d265ff 13/48: Fix the workaround for bug in xml-rpc.el, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi a5fa019e7f 21/48: url-scgi: Fix cl-check-type bug on Emacs 26.1, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi 2b22e6ffa9 11/48: url-scgi: Fix naming to not clutter namespace, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi a6ceb9f71d 14/48: Silence byte compiler warnings, ELPA Syncer, 2022/10/28
- [elpa] externals/url-scgi e9e8323d86 15/48: Use new 'cl-lib rather than old 'cl, ELPA Syncer, 2022/10/28