Skip to content
Raku HTTP::Server::Async
Other Shell
  1. Other 99.8%
  2. Shell 0.2%
Branch: master
Clone or download

Latest commit

Latest commit 9865805 Feb 12, 2019


Type Name Latest commit message Commit time
Failed to load latest commit information.
examples fix issue #33 Feb 10, 2019
lib/HTTP/Server rename to use -> HTTP::Roles instead Feb 10, 2019
t Add a META test Feb 12, 2019
.gitignore Add .precomp .gitignore Oct 28, 2016
.travis.yml Panda is deprecated and CI fails, switched to zef. Jun 17, 2017
META6.json Move the source Feb 12, 2019 Updated build status in Readme Feb 12, 2019
ab.pl6 now with time outs Aug 5, 2015 fixing and examples Sep 18, 2014


Build Status

Asynchronous HTTP server.

Currently handles:

  • Parsing Headers
  • Chunked Transfer
  • Hooks for middleware or route handling
  • Simple response handling

Doesn't handle


use HTTP::Server::Async;

my $s =;

$s.handler(sub ($request, $response) {
  $response.headers<Content-Type> = 'text/plain';
  $response.status = 200;
  $response.write("Hello ");
  $response.close("world!"); #keeps a promise in the response and ends the server handler processing




:port - port to listen on :host - ip to listen on :buffered - Boolean value for whether responses should be buffered or not

.handler ( Callable($request, $response) )

Any Callable 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 True to continue processing. A False value will discontinue processing. Alternatively a promise can be returned, if the promise is broken then the server will discontinue, if the promise is kept then processing will continue.

Callable will receive two parameters from the server, a HTTP::Server::Async::Request and a HTTP::Server::Async::Response. More about the Response and Request object below.

Note that the server will wait for the request body to be complete before calling handler subs.

.middleware ( Callable($request, $response) )

The same as the handler except will NOT wait for a complete request body. The middleware can hijack the connection by explicitly returning False and continuing processing using $request.connection to gain control of the socket.

.listen ( Bool $block? = False )

Starts the server and does not block


This handles the parsing of the incoming request





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


$.buffered (Bool) = True

Whether or not the response object should buffer the response and write on close, or write directly to the socket

$.status (Int)

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 socket, 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

Closing Credits

thanks to ugexe, btyler, jnthn, and timotimo for helping figure out bugs, answer a bunch of questions, etc

You can’t perform that action at this time.