Skip to content

Instantly share code, notes, and snippets.

@tom-lpsd
Created April 21, 2009 16:21
Show Gist options
  • Save tom-lpsd/99221 to your computer and use it in GitHub Desktop.
Save tom-lpsd/99221 to your computer and use it in GitHub Desktop.
(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