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

[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



reply via email to

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