#hs.httpserver.hsminweb
Minimalist Web Server for Hammerspoon
This module aims to be a minimal, but (mostly) standards-compliant web server for use within Hammerspoon. Expanding upon the Hammerspoon module, hs.httpserver
, this module adds support for serving static pages stored at a specified document root as well as serving dynamic content from Lua Template Files interpreted within the Hammerspoon environment and external executables which support the CGI/1.1 framework.
This module aims to provide a fully functional, and somewhat extendable, web server foundation, but will never replace a true dedicated web server application. Some limitations include:
- It is single threaded within the Hammerspoon environment and can only serve one resource at a time
- As with all Hammerspoon modules, while dynamic content is being generated, Hammerspoon cannot respond to other callback functions -- a complex or time consuming script may block other Hammerspoon activity in a noticeable manner.
- All document requests and responses are handled in memory only -- because of this, maximum resource size is limited to what you are willing to allow Hammerspoon to consume and memory limitations of your computer.
While some of these limitations may be mitigated to an extent in the future with additional modules and additions to hs.httpserver
, Hammerspoon's web serving capabilities will never replace a dedicated web server when volume or speed is required.
An example web site is provided in the hsdocs
folder of the hs.doc
module. This web site can serve documentation for Hammerspoon dynamically generated from the json file included with the Hammerspoon application for internal documentation. It serves as a basic example of what is possible with this module.
You can start this web server by typing the following into your Hammerspoon console: require("hs.doc.hsdocs").start()
and then visiting http://localhost:12345/
with your web browser.
#Submodules
#API Overview
Constants - Useful values which cannot be changed
Variables - Configurable values
Functions - API calls offered directly by the extension
Constructors - API calls which return an object, typically one that offers API methods
Methods - API calls which can only be made on an object returned by a constructor
- accessList
- allowDirectory
- bonjour
- cgiEnabled
- cgiExtensions
- directoryIndex
- dnsLookup
- documentRoot
- interface
- luaTemplateExtension
- maxBodySize
- name
- password
- port
- queryLogging
- scriptTimeout
- ssl
- start
- stop
#API Documentation
#Constants
Signature | hs.httpserver.hsminweb.dateFormatString |
Type | Constant |
Description | A format string, usable with os.date , which will display a date in the format expected for HTTP communications as described in RFC 822, updated by RFC 1123. |
Notes | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1592 |
Signature | hs.httpserver.hsminweb.statusCodes |
Type | Constant |
Description | HTTP Response Status Codes |
Notes |
|
Source | extensions/httpserver/httpserver_hsminweb.lua line 1644 |
#Variables
Signature | hs.httpserver.hsminweb._accessLog |
Type | Variable |
Description | Accessed as self._accessLog . If query logging is enabled for the web server, an Apache style common log entry will be appended to this string for each request. See hs.httpserver.hsminweb:queryLogging. |
Notes | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1552 |
Signature | hs.httpserver.hsminweb._errorHandlers |
Type | Variable |
Description | Accessed as self._errorHandlers[errorCode] . A table whose keyed entries specify the function to generate the error response page for an HTTP error. |
Notes | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1556 |
Signature | hs.httpserver.hsminweb._serverAdmin |
Type | Variable |
Description | Accessed as self._serverAdmin . A string containing the administrator for the web server. Defaults to the currently logged in user's short form username and the computer's localized name as returned by hs.host.localizedName() (e.g. "user@computer"). |
Notes | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1546 |
Signature | hs.httpserver.hsminweb._supportMethods |
Type | Variable |
Description | Accessed as self._supportMethods[method] . A table whose keyed entries specify whether or not a specified HTTP method is supported by this server. |
Notes | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1574 |
Signature | hs.httpserver.hsminweb.log |
Type | Variable |
Description | The hs.logger instance for the hs.httpserver.hsminweb module. See the documentation for hs.logger for more information. |
Notes | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1639 |
#Functions
Signature | hs.httpserver.hsminweb.formattedDate([date]) -> string |
Type | Function |
Description | Returns the current or specified time in the format expected for HTTP communications as described in RFC 822, updated by RFC 1123. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1597 |
Signature | hs.httpserver.hsminweb.urlParts(url) -> table |
Type | Function |
Description | Parse the specified URL into its constituent parts. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1608 |
#Constructors
Signature | hs.httpserver.hsminweb.new([documentRoot]) -> hsminwebTable |
Type | Constructor |
Description | Create a new hsminweb table object representing a Hammerspoon Web Server. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1505 |
#Methods
Signature | hs.httpserver.hsminweb:accessList([table]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the access-list table for the hsminweb web server |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1367 |
Signature | hs.httpserver.hsminweb:allowDirectory([flag]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the whether or not a directory index is returned when the requested URL specifies a directory and no file matching an entry in the directory indexes table is found. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1183 |
Signature | hs.httpserver.hsminweb:bonjour([flag]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the whether or not the web server should advertise itself via Bonjour when it is running. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1156 |
Signature | hs.httpserver.hsminweb:cgiEnabled([flag]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the whether or not CGI file execution is enabled. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1277 |
Signature | hs.httpserver.hsminweb:cgiExtensions([table]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the file extensions which identify files which should be executed as CGI scripts to provide the results to an HTTP request. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1297 |
Signature | hs.httpserver.hsminweb:directoryIndex([table]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the file names to look for when the requested URL specifies a directory. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1254 |
Signature | hs.httpserver.hsminweb:dnsLookup([flag]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the whether or not DNS lookups are performed. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1206 |
Signature | hs.httpserver.hsminweb:documentRoot([path]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the document root for the web server. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1104 |
Signature | hs.httpserver.hsminweb:interface([interface]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the network interface that the hsminweb web server will listen on |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1417 |
Signature | hs.httpserver.hsminweb:luaTemplateExtension([string]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the extension of files which contain Lua code which should be executed within Hammerspoon to provide the results to an HTTP request. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1320 |
Signature | hs.httpserver.hsminweb:maxBodySize([size]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the maximum body size for an HTTP request |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1075 |
Signature | hs.httpserver.hsminweb:name([name]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the name the web server uses in Bonjour advertisement when the web server is running. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1020 |
Signature | hs.httpserver.hsminweb:password([password]) -> hsminwebTable | boolean |
Type | Method |
Description | Set a password for the hsminweb web server, or return a boolean indicating whether or not a password is currently set for the web server. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1045 |
Signature | hs.httpserver.hsminweb:port([port]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the name the port the web server listens on |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 992 |
Signature | hs.httpserver.hsminweb:queryLogging([flag]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the whether or not requests to this web server are logged. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1230 |
Signature | hs.httpserver.hsminweb:scriptTimeout([integer]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the timeout for a CGI script |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1343 |
Signature | hs.httpserver.hsminweb:ssl([flag]) -> hsminwebTable | current-value |
Type | Method |
Description | Get or set the whether or not the web server utilizes SSL for HTTP request and response communications. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1128 |
Signature | hs.httpserver.hsminweb:start() -> hsminwebTable |
Type | Method |
Description | Start serving pages for the hsminweb web server. |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1448 |
Signature | hs.httpserver.hsminweb:stop() -> hsminwebTable |
Type | Method |
Description | Stop serving pages for the hsminweb web server. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/httpserver_hsminweb.lua line 1479 |