![]() |
Qore HttpServer Module Reference 1.5.2
|
The HttpServer module provides a multi-threaded HTTP server to Qore programs.
The HttpServer implemented is designed for serving REST, RPC-style, and file-system-based requests as well as other types of traffic with an appropriate handler (for example handlers requiring protocol changes such as with the WebSocket protocol are supported as well).
The HttpServer module supports async I/O and HTTP/2. Async I/O mode uses a non-blocking I/O controller to accept connections and read headers efficiently, then dispatches request processing to the thread pool. HTTP/2 support requires async I/O mode; when async I/O is disabled, the server only supports HTTP/1.x. Enable async I/O with the "async_mode" key in HttpServerOptionInfo and see the HttpServerAsyncIo module for additional details.
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 is (see HttpServerUtil for supporting definitions; note that the HttpServerUtil module's definitions are also imported into Program objects requiring this module):
HttpServer::HttpServer "HttpServer": this class implements the main interface to the HTTP server provided by this moduleSee also:
br) and Zstandard (zstd) Content-Encoding support (issue 5071)Accept-Encoding headers"listener-name" to the context hashHttpServer::HttpServer::addListeners() "HttpServer::addListeners()" has no mechanism for returning errors to the caller (issue 4312)"header-info" hash to the context argument when calling handlers (issue 3026)HttpServer::HttpServer::addHttpMethod() "HttpServer::addHttpMethod()" method (issue 2805)HEAD and other responses that cannot have a message body (bug 3116)"PATCH" methodHttpServer::HttpServer::addListener() would not accept port 0 meaning bind on any random open port (bug 1284)HttpServer::HttpServer::setReplyHeaders() where the Socket encoding was not set properly and therefore the encoding in the Content-Type in the response header did not necessarily match the encoding of the responsereexport option) and santized APIs, made HttpListener class private/internal againHttpServer::HttpServer::addListeners() "HttpServer::addListeners(string, hash, *code, *code, *code, *string, int)"HttpServer::HttpServer::addListener() with an integer argument; a UNIX socket was opened instead of a wildcard listener on the given portHttpServer::HttpServer::listenerStarted() method to allow for reporting when listeners are actually running since they are started asynchronously"ssl" key to the listener socket info hashHttpServer::HttpServer::addListeners() and both IPv6 and IPv4 addresses are returned, bind both addresses since Windows doesn't direct the IPv4 requests to the wildcard-bound IPv6 listenerContent-Encoding compression to HttpServer"&" and ";" as argument separatorsPUT and DELETE methods and for optional message bodies independent of the HTTP methodConnection header if present from the handlerTCP_NODELAY by default and use socket shutdown when closing sockets insteadHttpServer::AbstractHttpRequestHandler::redirect() to help in generating 301 Moved Permanently messagesHttpServer::HttpServer::addListeners() "HttpServer::addListeners()" and HttpServer::addListenersWithHandler() methods"listener-id" to request context hash"identity" encoding (if anyone ever sends it)"charset=utf-8" to Content-Type header if not already present"text/html" to Content-Type header if no content-type is given by the handlerTCP_NODELAY on all sockets to ensure that clients get all data before closing the socket, especially in case of errorsContent-Type handlingContent-Encoding support"deflate" and "gzip" content-encoding