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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 18/119: 404 not found helper


From: Eric Schulte
Subject: [elpa] 18/119: 404 not found helper
Date: Mon, 10 Mar 2014 16:57:04 +0000

eschulte pushed a commit to branch master
in repository elpa.

commit 5c580976a9379d8447f64aba1395d12a67cd1993
Author: Eric Schulte <address@hidden>
Date:   Wed Dec 18 22:54:29 2013 -0700

    404 not found helper
---
 NOTES               |    4 ++--
 emacs-web-server.el |   14 ++++++++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/NOTES b/NOTES
index 95828f4..bb1d061 100644
--- a/NOTES
+++ b/NOTES
@@ -22,14 +22,14 @@ parse more than just the content-type headers.
 ** TODO non-multipart form data
 e.g., parameter strings
 
-** TODO some more convenience functionality [0/6]
+** TODO some more convenience functionality [1/6]
 - [ ] strip and parse URL query string
 - [ ] think about defaulting to (name . content) for form elements
 - [ ] maybe don't require a non-nil return to cancel the connection,
   [ ] rather only keep on an explicit :keep-alive
 - [ ] function to send a file (with mime handling)
 - [ ] function to send a string (with header handling)
-- [ ] send a 404 with some default text
+- [X] send a 404 with some default text
 
 ** TODO Lazy header processing
 Use lazy sequence functions for header a-list to avoid parsing all
diff --git a/emacs-web-server.el b/emacs-web-server.el
index aeb4ba8..013bec6 100644
--- a/emacs-web-server.el
+++ b/emacs-web-server.el
@@ -69,7 +69,7 @@ function.
 
 "
   (let ((server (make-instance 'ews-server :handler handler :port port))
-        (log (get-buffer-create log-buffer)))
+        (log (when log-buffer (get-buffer-create log-buffer))))
     (setf (process server)
           (apply
            #'make-network-process
@@ -79,7 +79,8 @@ function.
            :server t
            :nowait t
            :family 'ipv4
-           :plist (list :server server :log-buffer log)
+           :plist (append (list :server server)
+                          (when log (list :log-buffer log)))
            :log (when log
                   (lambda (proc client message)
                     (let ((c (process-contact client))
@@ -231,5 +232,14 @@ Currently CODE should be an HTTP status code, see
                               "500 Internal Server Error"))
   (throw 'close-connection :finished))
 
+(defun ews-send-404 (proc &rest msg-and-args)
+  "Send 404 \"Not Found\" to PROC with an optional message."
+  (ews-response-header proc 404
+    '("Content-type" . "text/plain"))
+  (process-send-string proc (if msg-and-args
+                                (apply #'format msg-and-args)
+                              "404 Not Found"))
+  (throw 'close-connection :finished))
+
 (provide 'emacs-web-server)
 ;;; emacs-web-server.el ends here



reply via email to

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