tulip.pkg.server module exports the
Registering this package provides the following method and field extensions.
ok, err = App:main(cq)
Takes control of the main loop of the App. Starts the web server, calling the App instance with the Request and Response instances for each request.
The http server instance is stored on the App.
f, Stream = Request:body()
Returns an iterator over the chunks of the body, with the read timeout (if any) applied to reading the whole body (i.e. iterating until the end). Throws an error if the body is already consumed.
s, err = Request:read_body(mode)
Reads the body based on the mode specified.
On error, returns nil and an error message. If mode is "a" and the raw_body field is set, returns it.
t, err = Request:decode_body([force_ct])
Decodes the body using the request's content-type or (if provided) force_ct to determine the decoder to use, and returns the resulting table. Also sets self.decoded_body field for future use, and returns it if already set.
Note that this fully reads the body, so if Request:read_body wasn't called yet, it will be called.
Returns nil, error on error.
The Stream instance of the request, from lua-http.
The address of the request's peer.
The http protocol version.
The authority part of the url.
The headers instance of the request, from lua-http.
The cookies for the request, in name-value pairs.
The http method of the request.
The request's raw (unparsed, unmodified) url.
The request's parsed url, with path, scheme, query fields, etc.
The read timeout as configured on the server package.
A table to store key-value pairs local to the Request.
ok, err = Response:_write_headers(hdrs[, eos[, deadline]])
Writes the headers. This function should not be called directly, it exists for extensibility (e.g. gzip middleware) to intercept writing headers before the write actually happens but after Response:write has set all expected values. It should return true on success, nil and an error message on error (it must not throw).
n, err = Response:_write_body(f[, deadline])
Writes the body. This function should not be called directly, it exists for extensibility (e.g. gzip middleware) to intercept writing the raw body bytes as called from Response:write. It should return the number of bytes written on success, nil and an error message on error (it must not throw).
n, err, started = Response:write(t)
Writes a response. Should not be mixed with calls to the low-level stream object.
If the request method was HEAD, no body gets written, but it does get processed to compute the content-length.
Returns the number of body bytes written on success (which may be 0), or nil and an error message. A third return value indicates if some data (e.g. headers) was written before the failure, by returning true in that case (falsy otherwise).
The headers instance of the response, from lua-http.
The Stream instance of the response, from lua-http.
The write timeout as configured on the server package.
The number of body bytes written.