HTTP 1.1 client & server protocol in Lua. Uses [sock] for I/O but you can bring your own.
GZip compression can be enabled with http.zlib = require'zlib'
.
This module only implements the actual protocol. For a working HTTP client and server based on this module, see [http_client] and [http_server].
Works in developement, not used 24/7 yet.
http:new(opt) -> http
Create a HTTP protocol object that should be used on a single freshly open HTTP or HTTPS connection to either perform HTTP requests on it (as client) or to read-in HTTP requests and send-out responses (as server).
The table opt
can contain:
tcp
the I/O API (required)
port
if client: server's port (optional)
https
if client: true
if using TLS (optional)
max_line_size
change the HTTP line size limit
Make a HTTP request object. The table opt
can contain:
host
vhost name
max_line_size
change the HTTP line size limit
close
close the connection after replying
content
, content_size
body: string, read function or cdata buffer
compress
false
: don't compress body
Send a request.
Receive server's response.
Receive a client's request.
Construct a HTTP response object.
The opt
table can contain:
close
close the connection (and tell client to)
content
, content_size
body: string, read function or cdata buffer
compress
false
: don't compress body
allowed_methods
allowed methods: {method->true}
(optional)
content_type
content type (optional)
Send a response.