Created
April 21, 2009 16:21
-
-
Save tom-lpsd/99221 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun not-found (process) | |
(process-send-string process | |
(concat "HTTP/1.1 404 Not Found\r\n" | |
"Content-Type: text/plain\r\n\r\n" | |
"Not Found")) | |
(delete-process process)) | |
(defvar boundary "-----------\n") | |
(defun httpd-filter (process string) | |
(if (string-match "^GET /.*\.ico" string) | |
(not-found process) | |
(progn | |
(switch-to-buffer | |
(generate-new-buffer (process-name process))) | |
(make-local-variable 'proc) | |
(setq proc process) | |
(local-set-key "\C-c\C-c" | |
(lambda () (interactive) | |
(process-send-region proc | |
(save-excursion | |
(goto-char (point-min)) | |
(search-forward boundary)) (point-max)) | |
(delete-process proc) | |
(kill-buffer nil))) | |
(insert (concat string boundary))))) | |
(defun httpd-start () | |
(interactive) | |
(make-network-process | |
:name "emacs-httpd" | |
:server t | |
:host 'local | |
:service 8080 | |
:filter 'httpd-filter)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment