[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
- [elpa] 05/119: stub out (but don't write any) tests, (continued)
- [elpa] 05/119: stub out (but don't write any) tests, Eric Schulte, 2014/03/10
- [elpa] 08/119: NOTES file for tasks and notes, Eric Schulte, 2014/03/10
- [elpa] 07/119: TODO: handle post data, Eric Schulte, 2014/03/10
- [elpa] 06/119: helper for HTTP headers, Eric Schulte, 2014/03/10
- [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 <=
- [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, 2014/03/10
- [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