tulip.handler module contains functions and tables related to implementation of web and worker handlers.
local handler = require 'tulip.handler'.
Default MIME type when unknown.
List mapping well-known file extensions to MIME types.
List mapping common HTTP status codes to standard status text.
handler.chain_middleware(mws, req, res[, last[, i]])
Starts a call to a chain of middleware, where mws is an array of middleware functions. This calls the middleware at index i with a next() function generated to call the following middleware, ending with a call to last() if it is non-nil. If is is not provided, it is set to 1.
handler.chain_wmiddleware(mws, msg[, last[, i]])
Starts a call to a chain of wmiddleware, where mws is an array of wmiddleware functions. This calls the wmiddleware at index i with a next() function generated to call the following wmiddleware, ending with a call to last() if it is non-nil. If i is not provided, it is set to 1.
f = handler.dir(path)
Returns a handler that serves a directory based on the first Request.pathargs argument, then calls the next middleware. Sets the content-type based on some well-known file extensions.
f = handler.errhandler(t)
Returns an HTTP error handler that accepts req, res, nxt, err and dispatches handling to the function indicated by t, where t is a table where keys are error codes (e.g. 'EINVALID') and values are either error handlers (accepting req, res, nxt, err) or a number that indicates the HTTP status code to return (the body will be set to the default text of that status code).
If the error does not correspond to any of the defined error codes, the handler at array position 1 is called (or if it's a number, it is used as status code), or if it is not set, the error is thrown.
f = handler.recover(f)
Returns a handler that recovers from an error raised in subsequent middleware, and calls f with req, res and the error. Note that there is no next function argument in the arguments to f.
Writes a cookie to the response. The cfg table may have the following fields:
f = handler.wrecover(f)
Returns a worker handler that recovers from an error raised in subsequent wmiddleware, and calls f with msg and the error. Note that there is no next function argument in the arguments to f.
f = handler.write(t)
Returns a handler that just calls Response:write with t and calls the next middleware.