NonGNU-devel ELPA - simple-httpd

simple-httpd Atom Feed

Description
Pure Elisp HTTP server
Latest
simple-httpd-1.5.1.0.20260430.94242.tar (.sig), 2026-Apr-30, 70.0 KiB
Maintainer
Philip Kaludercic <philipk@posteo.net>, Daniel Mendler <mail@daniel-mendler.de>
Website
https://github.com/skeeto/emacs-http-server
Browse ELPA's repository
CGit or Gitweb
All Dependencies
compat (.tar)
Badge

To install this package from Emacs, use package-install or list-packages.

Full description

Use `httpd-start' to start the web server.  Files are served from
`httpd-root' on port `httpd-port' using `httpd-ip-family' at host
`httpd-host'.  While the root can be changed at any time, the server
needs to be restarted in order for a port change to take effect.

Everything is performed by servlets, including serving
files.  Servlets are enabled by setting `httpd-servlets' to true
(default).  Servlets are four-parameter functions that begin with
"httpd/" where the trailing component specifies the initial path on
the server.  For example, the function `httpd/hello-world' will be
called for the request "/hello-world" and "/hello-world/foo".

The default servlet `httpd/' is the one that serves files from
`httpd-root' and can be turned off through redefinition or setting
`httpd-serve-files' to nil.  It is used even when `httpd-servlets'
is nil.

The four parameters for a servlet are process, URI path, GET/POST
arguments (alist), and the full request object (header
alist).  These are ordered by general importance so that some can be
ignored.  Two macros are provided to help with writing servlets.

 * `httpd-with-buffer' -- Creates a temporary buffer that is
   automatically served to the client at the end of the body.
   Additionally, `standard-output' is set to this output
   buffer.  For example, this servlet says hello,

    (defun httpd/hello-world (proc path &rest args)
      (httpd-with-buffer proc "text/plain"
        (insert "hello, " (file-name-nondirectory path))))

This servlet be viewed at http://localhost:8080/hello-world/Emacs

* `httpd-servlet' -- Similar to the above macro but totally hides the
  process object from the servlet itself.  The above servlet can be
  re-written identically like so,

    (httpd-servlet hello-world text/plain (path)
      (insert "hello, " (file-name-nondirectory path)))

Note that `httpd-servlet' automatically sets `httpd-current-proc'.
See below.

The "function parameters" part can be left empty or contain up to
three parameters corresponding to the final three servlet
parameters.  For example, a servlet that shows *scratch* and doesn't
need parameters,

    (httpd-servlet scratch text/plain ()
      (insert-buffer-substring (get-buffer-create "*scratch*")))

A higher level macro `httpd-servlet*' wraps this lower-level
`httpd-servlet' macro, automatically binding variables to components
of the request.  For example, this binds parts of the request path
and one query parameter.  Request components not provided by the
client are bound to nil.

    (httpd-servlet* packages/:package/:version text/plain (verbose)
      (insert (format "%s\n%s\n" package version))
      (princ (get-description package version))
      (when verbose
        (insert (format "%S" (get-dependencies package version)))))

It would be accessed like so,

    http://example.com/packages/foobar/1.0?verbose=1

Some support functions are available for servlets for more
customized responses.

  * `httpd-send-file'   -- serve a file with proper caching
  * `httpd-redirect'    -- redirect the browser to another url
  * `httpd-send-header' -- send custom headers
  * `httpd-error'       -- report an error to the client
  * `httpd-log'         -- log an object to the `httpd-log-buffer'

Some of these functions require a process object, which isn't
passed to `httpd-servlet' servlets.  Use t in place of the process
argument to use `httpd-current-proc' (like `standard-output').

If you just need to serve static from some location under some
route on the server, use `httpd-file-servlet'.  It expands into
a `httpd-servlet' that serves files.

Old versions

simple-httpd-1.5.1.0.20260430.10256.tar.lz2026-Apr-3014.6 KiB
simple-httpd-1.5.1.0.20260429.183229.tar.lz2026-Apr-2914.7 KiB
simple-httpd-1.5.1.0.20260429.50652.tar.lz2026-Apr-2913.4 KiB

News

Development

  • Depend on Compat, update for new Emacs versions.
  • httpd-servlet, httpd-servlet*, httpd-file-servlet, httpd-with-buffer: Alternative name for defservlet, defservlet*, httpd-def-file-servlet and with-httpd-buffer respectively.
  • httpd-log-buffer: New customizable variable for the log buffer. Optimize httpd-log if the log buffer is disabled.
  • httpd-html, httpd-error: Numeric and textual status code are passed as arguments to format. Add default error page.
  • Store server and client processes and shutdown all processes in httpd-stop.
  • Parse body as arguments only for mime type application/x-www-form-urlencoded.
  • Reduce creation of temporary buffers and improve performance.
  • Improve parser robustness with additional checks.
  • Improve asynchronous request handling, maintaining a queue of requests.

Version 1.5.1: improvements

  • Add httpd-running-p
  • Properly handle "Connection: close" and HTTP/1.0

Version 1.5.0: improvements

  • Drastically improved performance for large requests
  • More HTTP status codes

Version 1.4.6: fixes

  • Added httpd-serve-directory
  • Fix some encoding issues

Version 1.4.5: fixes

  • Update to cl-lib from cl

Version 1.4.4: features

  • Common Lisp &key-like defservlet* argument support
  • Fix up some defservlet* usage warnings.

Version 1.4.3: features

  • Add httpd-discard-buffer
  • Add httpd-def-file-servlet
  • Be more careful about not sending extra headers

Version 1.4.2: features, fixes

  • defservlet* macro

Version 1.4.1: small bug fixes, one feature

  • All mime-type parameters now accept string designators
  • Documentation update

Version 1.4.0: features, API change, and fixes

  • Removed httpd-send-buffer; httpd-send-header now does this implicitly
  • httpd-send-header now accepts keywords instead
  • Fix httpd-clean-path in Windows
  • Fix a content-length bug
  • defservlet fontification

Version 1.3.1: features and fixes

  • Set standard-output in with-httpd-buffer

Version 1.3.0: security fix

  • Fix path expansion security issue
  • Fix coding system (don't default)

Version 1.2.4: fixes

  • Handle large POSTs
  • Fix date strings