Note This module is deprecated. It needs a complete rewrite before it's usable. If you want to do so, please feel free to make a pull request.
HTTP server.
- Parsing Headers
- Chunked Transfer
- Hooks for middleware or route handling
- Simple response handling
- Route handling
use HTTP::Server::Threaded;
my $s = HTTP::Server::Threaded.new;
$s.handler(sub ($request, $response) {
$response.headers<Content-Type> = 'text/plain';
$response.status = 200;
$response.write("Hello ");
$response.close("world!");
});
$s.listen;
:port
- port to listen on
:host
- ip to listen on
Any Sub
passed to this method is called in the order it was registered on every incoming request. Any method/sub registered with the server should ````return False;``` when the server should discontinue processing the request or close the request to discontinue processing.
Callable will receive two parameters from the server, a HTTP::Server::Threaded::Request
and a HTTP::Server::Threaded::Response
and a Sub
. More about the Response
and Request
object below.
If the server runs out of handlers or a handler not explicitly closing the connection and also returning False will leave the connection open.
Note that the server will wait for the request body to be complete before calling handler
subs.
If the .handler returns a Promise
then the server waits for the Promise to be kept with a True or False value before continuing
Same as .handler
but is called directly following header's being parsed.
If the middleware sub returns a False value, then the server will stop processing further data and leave the connection open. This allows a connections to be hijacked by middleware for streaming or whatever you want to do with it.
If the middleware returns a Promise
then the server waits for the Promise to be kept with a True or False value before continuing
Starts the server and does block
This handles the parsing of the incoming request
GET/PUT/POST/etc
Key/value pair containing the header values
Requested resource
HTTP/1.1
or HTTP/1.0
(or whatever was in the request)
String containing the data included with the request
Response object, handles writing and closing the socket
Whether or not the response object should buffer the response and write on close, or write directly to the socket
Set the status of the response, uses HTTP status codes. See here for more info
Response headers to be sent, accessed directly. Modifying these after writing to the socket will have no effect on the response unless the $.buffered
is set to True
Write data to the sucket, will call the appropriate method for the socket (Str = $connection.write, anything else is $connection.send)
Close takes optional parameter of data to send out. Will call write
if a parameter is provided. Closes the socket, writes headers if the response is buffered, etc