246 namespace HttpServer {
259 class HttpServer::HandlerInfo {
276 bool matchContentType(
string ct);
280 int matchRequest(
hash hdr,
int score);
285 class HttpServer::HttpHandlerList {
310 *HandlerInfo findHandler(
hash hdr, reference<int> score,
bool finalv =
False, *reference<string> root_path);
321 class HttpServer::DynamicHandlerInfo :
public HttpServer::HandlerInfo {
334 class HttpServer::DynamicHandlerHelper {
346 constructor(Counter n_c);
354 class HttpServer::DynamicHttpHandlerList :
public HttpServer::HttpHandlerList {
367 removeHandler(
string name);
370 *DynamicHandlerInfo findHandler(
hash hdr, reference<int> score, reference<DynamicHandlerHelper> dhh, *reference<string> root_path);
412 "deflate":
"deflate",
415 "x-deflate":
"deflate",
463 Sequence seqSessions();
464 Sequence seqListeners();
466 bool stopped =
False;
469 HttpHandlerList handlers();
490 DynamicHttpHandlerList dhandlers();
499 *
string override_encoding;
501 string http_server_string;
525 setDefaultTextEncoding(
string enc);
528 string getDefaultTextEncoding();
609 hash addListener(softstring sock, *
string cert_path, *
string key_path, *
string name,
int family =
AF_UNSPEC, *
string pwd);
629 softlist
addListeners(softstring sock, *
string cert_path, *
string key_path, *
string name,
int family =
AF_UNSPEC, *
string pwd);
648 list addINETListeners(*
string node, softstring service, *
string cert_path, *
string key_path, *
string name,
int family =
AF_UNSPEC, *
string pwd);
881 startConnection(code c);
921 static final hash getSSLObjects(
string cert_path, *
string key_path, *
string pwd);
928 final list addINETListenersIntern(*
string node, softstring service, *
hash sd, *
hash lp, *code logger, *code errorlogger, *code stopc, *
string name,
int family =
AF_UNSPEC);
935 final hash<HttpResponseInfo> noHandlerError(
hash cx,
hash hdr,
auto body);
941 final handleRequest(
HttpListener listener, Socket s, reference<hash> cx,
hash hdr,
hash hh, *data body,
bool head =
False, HttpPersistentHandlerInfo phi);
951 class HttpServer::HttpPersistentHandlerInfo {
955 *DynamicHandlerHelper dhh;
979 *SSLCertificate cert;
988 bool stopped =
False;
1007 bool log_recv_headers =
False;
1010 bool log_recv_body =
False;
1013 bool log_send_headers =
False;
1016 bool log_send_body =
False;
1018 const PollInterval = 1s;
1019 const ListenQueue = 100;
1020 const BodyLogLimit = 40;
1029 HttpHandlerList handlers();
1032 *HandlerInfo defaultHandler;
1037 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);
1040 addHandlers(
hash hi);
1043 setDefaultHandler(
string name);
1052 logRecvHeaders(softbool flag =
True);
1055 logRecvBody(softbool flag =
True);
1058 logSendHeaders(softbool flag =
True);
1061 logSendBody(softbool flag =
True);
1064 hash getLogOptions();
1082 auto removeUserThreadContext(*
string k);
1085 addUserThreadContext(
hash uctx);
1094 logResponse(
hash cx,
int code, *data body, *
hash hdr);
1103 logError(
string fmt);
1115 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
string get_exception_string(hash ex)
returns a multi-line string from the exception hash argument suitable for logging or output on the co...
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
setListenerLogOptionsUnlocked(softstring id, int code)
turns on or off header and body logging options for the given listener according to the option code ...
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:382
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:435
const DefaultIdleThreads
default number of idle threads to have waiting for new connections (accross all listeners) ...
Definition: HttpServer.qm.dox.h:420
stopListener(softstring bind)
stops a single listener based on its name or bind address; does not return until all connections on t...
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:394
stop()
stops all listeners; only returns when all connections are closed on all listeners ...
static nothing setReplyHeaders(Socket s, hash cx, reference< hash > rv)
helper method to set HTTP response headers
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:444
const PollTimeout
default poll timeout in ms
Definition: HttpServer.qm.dox.h:384
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:438
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
int getListenerLogOptionsUnlocked(softstring id)
returns header and body logging options for the given listener as a binary-or'ed value of listener lo...
const CompressionThreshold
default threadhold for data compressions; transfers smaller than this size will not be compressed ...
Definition: HttpServer.qm.dox.h:423
waitStop()
waits for all listeners to be stopped; call after calling HttpServer::stopNoWait() ...
setMaskCode(code maskfunc)
sets the closure or call reference that will be used to mask sensitive data in log messages ...
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
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:391
copy()
throws an exception; these objects do not support copying
const Version
version of the HttpServer's implementation
Definition: HttpServer.qm.dox.h:380
string maskData(string msg)
masks log messages by removing sensitive data
The HttpServer class implements a multithreaded HTTP server.
Definition: HttpServer.qm.dox.h:375
int getListenerCount()
returns the number of running HTTP listeners
this class implements the listeners for the HttpServer class
Definition: HttpServer.qm.dox.h:973
listenerStarted(int id, hash sinfo)
called from listener when the actual listener thread is running
int getListenerIdFromBindUnlocked(string bind)
returns the listener ID from the bind name or throws an exception if not valid
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:407
const LLO_SEND_HEADERS
listener log option: log send headers
Definition: HttpServer.qm.dox.h:441
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:410
int getListenerTID(softint id)
gets the TID of a listener based on its listener ID