254 class HttpServer::HandlerInfo {
271 bool matchContentType(
string ct);
275 int matchRequest(
hash hdr,
int score);
280 class HttpServer::HttpHandlerList {
291 static checkSpecialHeaders(reference sh);
300 *HandlerInfo findHandler(
hash hdr, reference score,
bool finalv =
False, *reference root_path);
311 class HttpServer::DynamicHandlerInfo :
public HttpServer::HandlerInfo {
324 class HttpServer::DynamicHandlerHelper {
336 constructor(Counter n_c);
344 class HttpServer::DynamicHttpHandlerList :
public HttpServer::HttpHandlerList {
357 removeHandler(
string name);
360 *DynamicHandlerInfo findHandler(
hash hdr, reference score, reference dhh, *reference root_path);
401 "deflate":
"deflate",
404 "x-deflate":
"deflate",
449 Sequence seqSessions();
450 Sequence seqListeners();
452 bool stopped =
False;
455 HttpHandlerList handlers();
476 DynamicHttpHandlerList dhandlers();
485 *
string override_encoding;
487 string http_server_string;
511 setDefaultTextEncoding(
string enc);
514 string getDefaultTextEncoding();
595 hash addListener(softstring sock, *
string cert_path, *
string key_path, *
string name,
int family =
AF_UNSPEC, *
string pwd);
615 softlist
addListeners(softstring sock, *
string cert_path, *
string key_path, *
string name,
int family =
AF_UNSPEC, *
string pwd);
634 list addINETListeners(*
string node, softstring service, *
string cert_path, *
string key_path, *
string name,
int family =
AF_UNSPEC, *
string pwd);
844 startConnection(code c);
870 static final private hash getSSLObjects(
string cert_path, *
string key_path, *
string pwd);
873 final private list addINETListenersIntern(*
string node, softstring service, *
hash sd, *
hash lp, *code logger, *code errorlogger, *code stopc, *
string name,
int family =
AF_UNSPEC);
877 final private hash noHandlerError(
hash cx,
hash hdr, any body);
882 final handleRequest(
HttpListener listener, Socket s, reference cx,
hash hdr,
hash hh, *data body,
bool head =
False, HttpPersistentHandlerInfo phi);
892 class HttpServer::HttpPersistentHandlerInfo {
896 *DynamicHandlerHelper dhh;
920 *SSLCertificate cert;
929 bool stopped =
False;
948 bool log_recv_headers =
False;
951 bool log_recv_body =
False;
954 bool log_send_headers =
False;
957 bool log_send_body =
False;
959 const PollInterval = 1s;
960 const ListenQueue = 100;
969 HttpHandlerList handlers();
972 *HandlerInfo defaultHandler;
977 constructor(
HttpServer n_server,
int n_id, Sequence n_ss, *
string n_node, *softstring n_service, *
Qore::SSLCertificate n_cert, *
Qore::SSLPrivateKey n_key, *
hash n_hi, *code n_logger, *code n_errorlogger, *code n_stopc,
string n_name,
int n_family =
AF_UNSPEC);
980 addHandlers(
hash hi);
983 setDefaultHandler(
string name);
992 logRecvHeaders(softbool flag =
True);
995 logRecvBody(softbool flag =
True);
998 logSendHeaders(softbool flag =
True);
1001 logSendBody(softbool flag =
True);
1004 hash getLogOptions();
1022 any removeUserThreadContext(*
string k);
1025 addUserThreadContext(
hash uctx);
1034 logResponse(
hash cx,
int code, *data body, *
hash hdr);
1043 logError(
string fmt);
1046 private mainThread();
1050 private connectionThread(Socket s);
log(string fmt)
called to log information to the registered log code
hash addListener(softstring sock, *string cert_path, *string key_path, *string name, int family=AF_UNSPEC, *string pwd)
adds a global listener to the server
hash getListeners()
returns a hash of listener information
int getListenerLogOptions(softstring bind)
returns a binary-or'ed product of listener log options corresponding to enabled log options for the g...
addHandlerToListener(softstring bind, string name, string path, *softlist content_type, HttpServer::AbstractHttpRequestHandler obj, *softlist special_headers, bool isregex=True)
adds a request handler to a listener given the listener's name or bind address
string get_exception_string(hash ex)
returns a multi-line string from the exception hash argument suitable for logging or output on the co...
setDebug(bool dbg=True)
turns on or off debugging; when debugging is enabled more verbose error messages are reported ...
static string getURLFromBind(softstring bind, *string host)
returns a complete URL from a bind address
const ReadTimeout
default read timeout in ms
Definition: HttpServer.qm.dox.h:372
removeDynamicHandler(string name)
remove dynamic handler
constructor(*code n_logfunc, *code n_errlogfunc, bool n_dbg=False, string n_name=HttpServer::HttpServerString, hash n_hdr=("X-Powered-By":"Qore/"+Qore::VersionString))
creates the HttpServer
destructor()
calls stop() and destroys the object
const LLO_RECV_HEADERS
listener log option: log recv headers
Definition: HttpServer.qm.dox.h:424
const DefaultIdleThreads
default number of idle threads to have waiting for new connections (accross all listeners) ...
Definition: HttpServer.qm.dox.h:409
stopListener(softstring bind)
stops a single listener based on its name or bind address; does not return until all connections on t...
private setListenerLogOptionsUnlocked(softstring id, int code)
turns on or off header and body logging options for the given listener according to the option code ...
stopListenerID(softint id)
stops a single listener based on its listener ID; does not return until all connections on the listen...
const HttpMethods
supported HTTP methods
Definition: HttpServer.qm.dox.h:384
stop()
stops all listeners; only returns when all connections are closed on all listeners ...
final list addListenersWithHandler(string hname, HttpServer::AbstractHttpRequestHandler handler, hash lp, *code logger, *code errorlogger, *code stopc, *string name, int family=AF_UNSPEC)
adds a dedicated listener to the server with an explicit/dedicated handler for incoming connections ...
hash getListenerInfo(softint id)
returns a hash of information about the listener given the listener ID
setListenerLogOptions(softstring bind, softint code)
turns on or off header and body logging options for receive operations for the given listener ...
const LLO_SEND_BODY
listener log option: log sent message body
Definition: HttpServer.qm.dox.h:433
const PollTimeout
default poll timeout in ms
Definition: HttpServer.qm.dox.h:374
final list addListeners(string bind, hash lp, *code logger, *code errorlogger, *code stopc, *string name, int family=AF_UNSPEC)
adds a dedicated listener to the server with an explicit/dedicated handler for incoming connections ...
logError(string fmt)
called to log error information to the registered error log code
nothing exit(softint rc=0)
static string getHttpServerVersionString()
returns the HTTP server version string
sendHttpError(HttpListener listener, hash cx, Socket s, int code, string msg, *hash extra_hdrs, *string encoding)
sends an HTTP error message on the socket
int getListenerLogOptionsID(softint id)
returns a binary-or'ed product of listener log options corresponding to enabled log options for the g...
const LLO_RECV_BODY
listener log option: log recv message body
Definition: HttpServer.qm.dox.h:427
stopNoWait()
stops all listeners; does not wait for all connections on the listeners to close
bool getDebug()
returns the current status of the debug flag
setDynamicHandler(string name, string path, *softlist content_type, HttpServer::AbstractHttpRequestHandler obj, *softlist special_headers, bool isregex=True)
sets a dynamic request handler according to the arguments given
const CompressionThreshold
default threadhold for data compressions; transfers smaller than this size will not be compressed ...
Definition: HttpServer.qm.dox.h:412
waitStop()
waits for all listeners to be stopped; call after calling HttpServer::stopNoWait() ...
setHandler(string name, string path, *softlist content_type, HttpServer::AbstractHttpRequestHandler obj, *softlist special_headers, bool isregex=True)
sets a request handler according to the arguments given
static nothing setReplyHeaders(Socket s, hash cx, reference rv)
helper method to set HTTP response headers
list addINETListeners(*string node, softstring service, *string cert_path, *string key_path, *string name, int family=AF_UNSPEC, *string pwd)
adds one or more global listeners according to the bind address
const AIFlags
address info flags
Definition: HttpServer.qm.dox.h:381
copy()
throws an exception; these objects do not support copying
const Version
version of the HttpServer's implementation
Definition: HttpServer.qm.dox.h:370
The HttpServer class implements a multithreaded HTTP server.
Definition: HttpServer.qm.dox.h:365
the main namespace for the HttpServer module
int getListenerCount()
returns the number of running HTTP listeners
this class implements the listeners for the HttpServer class
Definition: HttpServer.qm.dox.h:914
private int getListenerIdFromBindUnlocked(string bind)
returns the listener ID from the bind name or throws an exception if not valid
listenerStarted(int id, hash sinfo)
called from listener when the actual listener thread is running
hash getListenerInfoName(string name)
returns a hash of information about the listener given the listener name or bind ID ...
addHandlerToListenerID(softint id, string name, string path, *softlist content_type, HttpServer::AbstractHttpRequestHandler obj, *softlist special_headers, bool isregex=True)
adds a request handler to a listener given the listener's id
setDefaultHandler(string name, HttpServer::AbstractHttpRequestHandler obj)
sets the default request handler when no other handler can be matched
const HttpCodes
map of HTTP result codes and text messages
Definition: HttpServer.qm.dox.h:396
const LLO_SEND_HEADERS
listener log option: log send headers
Definition: HttpServer.qm.dox.h:430
private int getListenerLogOptionsUnlocked(softstring id)
returns header and body logging options for the given listener as a binary-or'ed value of listener lo...
setListenerLogOptionsID(softint id, softint code)
turns on or off header and body logging options for receive operations for the given listener ...
const ContentEncodings
content-encodings supported; this is a hash to simulate a set with O(ln(n)) access times ...
Definition: HttpServer.qm.dox.h:399
int getListenerTID(softint id)
gets the TID of a listener based on its listener ID