[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 20/119: don't require non-nil return to close connection
From: |
Eric Schulte |
Subject: |
[elpa] 20/119: don't require non-nil return to close connection |
Date: |
Mon, 10 Mar 2014 16:57:05 +0000 |
eschulte pushed a commit to branch master
in repository elpa.
commit 524539296f799b1f533263c0aad4cdd0152ae019
Author: Eric Schulte <address@hidden>
Date: Wed Dec 18 23:06:35 2013 -0700
don't require non-nil return to close connection
---
NOTES | 11 ++++++++---
emacs-web-server.el | 15 ++++++++-------
2 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/NOTES b/NOTES
index 79022cc..7e5dbcd 100644
--- a/NOTES
+++ b/NOTES
@@ -22,10 +22,11 @@ parse more than just the content-type headers.
** TODO non-multipart form data
e.g., parameter strings
-** TODO some more convenience functionality [2/6]
+** TODO some more convenience functionality [3/6]
- [ ] strip and parse URL query string
- [X] think about defaulting to (name . content) for form elements
-- [ ] maybe don't require a non-nil return to cancel the connection,
+- [X] maybe don't require a non-nil return to cancel the connection,
+ instead only keep open if :keep-open is returned
[ ] rather only keep on an explicit :keep-alive
- [ ] function to send a file (with mime handling)
- [ ] function to send a string (with header handling)
@@ -44,4 +45,8 @@ I think this should work.
*** Matching
*** Handler Functions
At any time one can throw =close-connection= to abort the handler and
-close the conncetion.
+close the conncetion. If the keyword =:keep-open= is thrown, then the
+handler aborts, but the connection isn't closed.
+
+A return value of =:keep-open= will keep the connection open,
+otherwise it is closed when the handler returns.
diff --git a/emacs-web-server.el b/emacs-web-server.el
index 6b1e5dd..5af2ab2 100644
--- a/emacs-web-server.el
+++ b/emacs-web-server.el
@@ -131,11 +131,12 @@ function.
(unless (assoc proc clients)
(push (cons proc (make-instance 'ews-client)) clients))
(let ((client (cdr (assoc proc clients))))
- (when (catch 'close-connection
- (and (ews-do-filter client string)
- (ews-call-handler proc (cdr (headers client)) handler)))
- (setq clients (assq-delete-all proc clients))
- (delete-process proc)))))
+ (when (ews-do-filter client string)
+ (when (not (eq (catch 'close-connection
+ (ews-call-handler proc (cdr (headers client))
handler))
+ :keep-open))
+ (setq clients (assq-delete-all proc clients))
+ (delete-process proc))))))
(defun ews-do-filter (client string)
"Return non-nil when finished and the client may be deleted."
@@ -229,7 +230,7 @@ Currently CODE should be an HTTP status code, see
(process-send-string proc (if msg-and-args
(apply #'format msg-and-args)
"500 Internal Server Error"))
- (throw 'close-connection :finished))
+ (throw 'close-connection nil))
(defun ews-send-404 (proc &rest msg-and-args)
"Send 404 \"Not Found\" to PROC with an optional message."
@@ -238,7 +239,7 @@ Currently CODE should be an HTTP status code, see
(process-send-string proc (if msg-and-args
(apply #'format msg-and-args)
"404 Not Found"))
- (throw 'close-connection :finished))
+ (throw 'close-connection nil))
(provide 'emacs-web-server)
;;; emacs-web-server.el ends here
- [elpa] 09/119: parsing form data in POST, (continued)
- [elpa] 09/119: parsing form data in POST, Eric Schulte, 2014/03/10
- [elpa] 11/119: more flexible network process creation, Eric Schulte, 2014/03/10
- [elpa] 10/119: some simple examples, Eric Schulte, 2014/03/10
- [elpa] 15/119: more lenient parsing of multipart forms, Eric Schulte, 2014/03/10
- [elpa] 12/119: compiling to .elc, Eric Schulte, 2014/03/10
- [elpa] 13/119: tasks, Eric Schulte, 2014/03/10
- [elpa] 18/119: 404 not found helper, Eric Schulte, 2014/03/10
- [elpa] 17/119: handling errors, Eric Schulte, 2014/03/10
- [elpa] 14/119: better requirements for test, Eric Schulte, 2014/03/10
- [elpa] 16/119: tasks, Eric Schulte, 2014/03/10
- [elpa] 20/119: don't require non-nil return to close connection,
Eric Schulte <=
- [elpa] 19/119: simply (name . content) for form elements, Eric Schulte, 2014/03/10
- [elpa] 21/119: helper to send a file with mime type, Eric Schulte, 2014/03/10
- [elpa] 22/119: file serving example, Eric Schulte, 2014/03/10
- [elpa] 23/119: handle close-connection thrown during header parse, Eric Schulte, 2014/03/10
- [elpa] 25/119: seems to be generally usable, added a README, Eric Schulte, 2014/03/10
- [elpa] 24/119: parse application/x-www-form-urlencoded post data, Eric Schulte, 2014/03/10
- [elpa] 26/119: thread proc through some functions, Eric Schulte, 2014/03/10
- [elpa] 28/119: testing a hello-world server, Eric Schulte, 2014/03/10
- [elpa] 27/119: run test processes asynch, Eric Schulte, 2014/03/10
- [elpa] 29/119: update examples, Eric Schulte, 2014/03/10