The HttpServer module provides a multi-threaded HTTP server to Qore programs.
The HttpServer implemented here was designed mostly for serving RPC-style requests, however it can also be used to serve files with an appropriate handler.
It has not been audited for security.
To use this module, use "%requires HttpServer"
in your code. See examples/httpserver.q for an example program using this module
All the public symbols in the module are defined in the HttpServer namespace
The main classes are:
- Example:
#!/usr/bin/env qore
%requires HttpServer
%requires Mime
class MyHandler inherits AbstractHttpRequestHandler {
# NOTE: change "%y" to "%N" to get a more readable multi-line output format for container values
log("request received on %s from %s: context: %y hdr: %y body size: %d byte%s", $cx."peer-info".desc, $cx."socket-info".desc, $cx, $hdr, $body.size(), $body.size() == 1 ? "" : "s");
return (
"code": 200,
);
}
}
sub log(string $str) {
}
const MyHttpPort = 19001;
# create our handler object
my MyHandler $myHandler();
# create the http server object
my HttpServer $hs(\log(), \log());
# add our handler to the server
$hs.setHandler(
"my-handler",
"/",
MimeTypeHtml, $myHandler);
# set our handler as the default handler
$hs.setDefaultHandler("my-handler", $myHandler);
# start a listener
my
hash $lh = $hs.addListener(MyHttpPort);
# output a log message
log("started listener on %s", $lh.desc);