370 const PollTimeout = 250ms;
377 const AIFlags = AI_PASSIVE | AI_ADDRCONFIG;
380 const HttpMethods = {
396 const ContentEncodings = {
398 "deflate":
"deflate",
401 "x-deflate":
"deflate",
406 const DefaultIdleThreads = 10;
409 const CompressionThreshold = 1024;
421 const LLO_RECV_HEADERS = (1 << 0);
424 const LLO_RECV_BODY = (1 << 1);
427 const LLO_SEND_HEADERS = (1 << 2);
430 const LLO_SEND_BODY = (1 << 3);
444 Sequence seqSessions();
445 Sequence seqListeners();
447 bool stopped = False;
450 HttpHandlerList handlers();
453 hash<auto> defaultHandler;
456 hash<string, HttpListener> listeners;
459 hash<string, int> smap;
462 hash<string, int> nmap;
471 DynamicHttpHandlerList dhandlers();
474 ThreadPool threadPool(-1, DefaultIdleThreads);
482 *
string override_encoding;
485 string http_server_string;
488 hash<string, bool> http_methods = HttpMethods;
491 *LoggerInterface logger;
544 setDefaultTextEncoding(
string enc);
547 string getDefaultTextEncoding();
572 final list<hash<auto>>
addListeners(
string bind, hash<HttpListenerOptionInfo> info, *reference<hash<string, string>> errmap);
589 final list<hash<auto>>
addListeners(hash<HttpListenerOptionInfo> info, *reference<hash<string, string>> errmap);
925 sendHttpError(
HttpListener listener, hash<auto> cx, Socket s,
int code, *data msg, *InputStream chunked_msg, *hash<auto> extra_hdrs, *
string encoding,
bool head);
967 startConnection(code c);
996 final HttpListener addListenerIntern(*
string node, *softstring service, *
Qore::SSLCertificate cert, *
Qore::SSLPrivateKey key, *hash<
string, hash<HttpHandlerConfigInfo>> handler_info, *LoggerInterface logger, *code stopc, *
string name,
int family = AF_UNSPEC);
1001 final HttpListener addListenerIntern(hash<HttpListenerOptionInfo> info);
1007 final list<hash<auto>> addINETListenersIntern(hash<HttpListenerOptionInfo> info, *reference<hash<string, string>> errmap);
1013 final hash<HttpResponseInfo> noHandlerError(hash<auto> cx, hash<auto> hdr,
auto body);
1019 final handleRequest(
HttpListener listener, Socket s, reference<hash<auto>> cx, hash<auto> hdr,
bool head = False, HttpPersistentHandlerInfo phi, hash<auto> info, reference<bool> dedicated);
1029 doResponse(
HttpListener listener, Socket s, hash<auto> cx, hash rv);
1035class HttpPersistentHandlerInfo {
1038 *DynamicHandlerHelper dhh;
1061 *hash<HttpListenerOptionInfo> opts;
1075 bool stopped = False;
1079 hash<string, AbstractHttpSocketHandlerInterface> shh;
1093 bool log_recv_headers = False;
1096 bool log_recv_body = False;
1099 bool log_send_headers = False;
1102 bool log_send_body = False;
1113 const PollInterval = 250ms;
1114 const ListenQueue = 100;
1115 const BodyLogLimit = 40;
1118 int handler_ref_cnt = 0;
1121 HttpHandlerList handlers();
1125 SSL_VERIFY_PEER:
"SSL_VERIFY_PEER",
1126 SSL_VERIFY_FAIL_IF_NO_PEER_CERT:
"SSL_VERIFY_FAIL_IF_NO_PEER_CERT",
1127 SSL_VERIFY_CLIENT_ONCE:
"SSL_VERIFY_CLIENT_ONCE",
1136 *HandlerInfo defaultHandler;
1176 setDefaultHandler(
string name);
1179 *HandlerInfo findHandler(hash<auto> hdr, reference<int> score,
bool finalv = False, *reference<string> root_path);
1191 hash getListenerSocketInfo();
1200 logRecvHeaders(softbool flag = True);
1203 logRecvBody(softbool flag = True);
1206 logSendHeaders(softbool flag = True);
1209 logSendBody(softbool flag = True);
1212 doLogRecvBody(*data body, hash<auto> cx, hash<auto> hdr, hash<auto> info);
1215 hash<auto> getLogOptions();
1230 hash<auto> getInfo();
1239 softlist<string> getSslVerifyModeList();
1243 auto removeUserThreadContext(*
string k);
1246 addUserThreadContext(hash<auto> uctx);
1255 logResponse(hash<auto> cx,
int code, *data body, *hash<auto> hdr);
1258 logResponse(hash<auto> cx,
int code, InputStream body, *hash<auto> hdr);
1261 logResponse(hash<auto> cx, hash<auto> rv);
1267 logError(
string fmt);
1277 connectionThread(Socket s);
1300 *hash<string, bool> content_type_map;
1301 *list<string> special_header_list;
1306 constructor(
string name, hash<HttpHandlerConfigInfo> info);
1309 bool matchContentType(
string ct);
1313 int matchRequest(hash<auto> hdr,
int score);
1321class HttpHandlerList {
1324 hash<string, HandlerInfo> handlers;
1339 setHandler(
string name, hash<HttpHandlerConfigInfo> info);
1346 removeHandler(
string handler_name);
1357 *HandlerInfo findHandler(hash<auto> hdr, reference<int> score,
bool finalv = False, *reference<string> root_path);
1368class DynamicHandlerInfo :
public HandlerInfo {
1373 constructor(
string name, hash<HttpHandlerConfigInfo> info) ;
1378class DynamicHandlerHelper {
1388 constructor(Counter n_c);
1396class DynamicHttpHandlerList :
public HttpHandlerList {
1403 hash<string, bool> disable_map;
1408 setHandler(
string name, hash<HttpHandlerConfigInfo> info);
1414 removeHandler(
string name, *
bool force_immediate);
1420 disableHandler(
string name);
1423 *DynamicHandlerInfo findHandler(hash<auto> hdr, reference<int> score, reference<DynamicHandlerHelper> dhh, *reference<string> root_path);
1427class HttpServerCallbackAppender :
public LoggerAppenderWithLayout {
1435 constructor(code logfunc) ;
1438 processEventImpl(
int type,
auto params);
this class implements the listeners for the HttpServer class
Definition: HttpServer.qm.dox.h:1054
removeHandler(HttpServer::AbstractHttpRequestHandler handler)
const SslVerifyMap
map for converting ssl verify flags to strings
Definition: HttpServer.qm.dox.h:1124
constructor(HttpServer server, string name, int id, Sequence ss, *hash< HttpListenerOptionInfo > opts)
creates the object with the given parameters
static bool stopIfNoHandlers(HttpServer::HttpListener listener)
stop listeners if there are no handlers
removeHandler(string handler_name)
addHandlers(hash< string, hash< HttpHandlerConfigInfo > > handler_info)
add handlers to the listener
bool get_remote_certs
get remote certificates
Definition: HttpServer.qm.dox.h:1105
int ssl_verify_flags
SSL verify flags.
Definition: HttpServer.qm.dox.h:1108
bool ssl_accept_all_certs
accept all certificates
Definition: HttpServer.qm.dox.h:1111
reloadCertificate()
Reloads the HTTPS certificate from the original location.
*LoggerInterface logger
listener-specific logger; if not present, then the server's logger will be used
Definition: HttpServer.qm.dox.h:1085
constructor()
Creates the server with default options and an empty logger.
stopListenerID(softint id)
stops a single listener based on its listener ID; does not return until all connections on the listen...
const ReadTimeout
default read timeout in ms
Definition: HttpServer.qm.dox.h:368
hash< string, hash< auto > > getListeners()
returns a hash of listener information
static nothing setReplyHeaders(Socket s, hash< auto > cx, reference< hash< auto > > rv)
helper method to set HTTP response headers
disableDynamicHandler(string name)
Disable dynamic handler.
final list< hash< auto > > addListeners(string bind, hash< HttpListenerOptionInfo > info, *reference< hash< string, string > > errmap)
adds one or more dedicated listeners to the server with the given bind address
setMaskCode(code maskfunc)
sets the closure or call reference that will be used to mask sensitive data in log messages
addHandlerToListener(softstring bind, string name, hash< HttpHandlerConfigInfo > info)
adds a request handler to a listener given the listener's name or bind address
static string getHttpServerVersionString()
returns the HTTP server version string
setDefaultHandler(string name, HttpServer::AbstractHttpRequestHandler obj)
sets the default request handler when no other handler can be matched
removeDynamicHandler(string name, *bool force_immediate)
remove dynamic handler
int getListenerCount()
returns the number of running HTTP listeners
destructor()
calls stop() and destroys the object
hash< auto > addListener(hash< HttpListenerOptionInfo > opts)
adds a single global listener to the server
setDynamicHandler(string name, HttpServer::AbstractUrlHandler obj)
sets a dynamic request handler according to the arguments given
string maskData(string msg)
masks log messages by removing sensitive data
listenerStarted(int id, hash< auto > sinfo)
called from listener when the actual listener thread is running
bool removeHandlerFromListenerID(softstring id, HttpServer::AbstractHttpRequestHandler handler)
remove request handler from a listener given the listener's id
waitStop()
waits for all listeners to be stopped; call after calling HttpServer::stopNoWait()
deprecated constructor(*code logfunc, *code errlogfunc, bool dbg=False, string name=HttpServer::HttpServerString, hash< auto > hdr={ 'X-Powered-By':'Qore/'+Qore::VersionString})
creates the HttpServer
reloadListenerCertificate(int id)
Reloads an HTTPS certificate from the original location for the given listener from the listener ID.
hash< auto > getListenerInfoName(string name)
returns a hash of information about the listener given the listener name or bind ID
stopListener(softstring bind)
stops a single listener based on its name or bind address; does not return until all connections on t...
static string getURLFromBind(softstring bind, *string host)
returns a complete URL from a bind address
reloadListenerCertificateName(string name)
Reloads an HTTPS certificate from the original location for the given listener from the listener name...
copy()
throws an exception; these objects do not support copying
bool removeHandlerFromListenerID(softstring id, string handler_name)
remove request handler from a listener given the listener's id
logError(string fmt)
called to log error information to the registered error log code
setHandler(string name, string path, *softlist< softstring > content_types, HttpServer::AbstractHttpRequestHandler obj, *softlist< softstring > special_headers, bool isregex=True)
sets a request handler according to the arguments given
addHandlerToListenerID(softint id, string name, hash< HttpHandlerConfigInfo > info)
adds a request handler to a listener given the listener's id
constructor(hash< HttpServerOptionInfo > opts)
Creates the server with the given options.
addHttpMethod(string m)
add a new supported HTTP method
final list< hash< auto > > addListeners(hash< HttpListenerOptionInfo > info, *reference< hash< string, string > > errmap)
adds one or more dedicated listeners to the server with the given bind address
int getListenerTID(softint id)
gets the TID of a listener based on its listener ID
callListenerStopCallback(code stopc, string name, hash< auto > socket_info)
To call a listener's stop callback.
bool getDebug()
returns the current status of the debug flag
addHandlerToListenerID(softint id, string name, HttpServer::AbstractUrlHandler obj)
adds a request handler to a listener given the listener's id
setListenerLogOptions(softstring bind, softint code)
turns on or off header and body logging options for receive operations for the given listener
addHandlerToListener(softstring bind, string name, HttpServer::AbstractUrlHandler obj)
adds a request handler to a listener given the listener's name or bind address
setDebug(bool dbg=True)
turns on or off debugging; when debugging is enabled more verbose error messages are reported
const HttpCodes
map of HTTP result codes and text messages
Definition: HttpServer.qm.dox.h:393
hash< auto > addListener(int port)
adds a single global listener to the server
setHandler(string name, hash< HttpHandlerConfigInfo > info)
sets a request handler according to the arguments given
setListenerLogOptionsID(softint id, softint code)
turns on or off header and body logging options for receive operations for the given listener
sendHttpError(HttpListener listener, hash< auto > cx, Socket s, int code, *data msg, *InputStream chunked_msg, *hash< auto > extra_hdrs, *string encoding, bool head)
sends an HTTP error message on the socket
log(string fmt)
called to log information to the registered log code
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
setDynamicHandler(string name, string path, *softlist< softstring > content_types, HttpServer::AbstractHttpRequestHandler obj, *softlist< softstring > 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...
int getListenerLogOptions(softstring bind)
returns a binary-or'ed product of listener log options corresponding to enabled log options for the g...
stopNoWait()
stops all listeners; does not wait for all connections on the listeners to close
stopListenerIDNoWait(softint id)
starts the shutdown process for a listener based on its listener ID; returns immediately
int getListenerLogOptionsID(softint id)
returns a binary-or'ed product of listener log options corresponding to enabled log options for the g...
setHandler(string name, HttpServer::AbstractUrlHandler obj)
sets a request handler according to the arguments given
setListenerLogOptionsUnlocked(softstring id, int code)
turns on or off header and body logging options for the given listener according to the option code
stop()
stops all listeners; only returns when all connections are closed on all listeners
hash< auto > getListenerInfo(softint id)
returns a hash of information about the listener given the listener ID
int getListenerIdFromBindUnlocked(string bind)
returns the listener ID from the bind name or throws an exception if not valid
setDynamicHandler(string name, hash< HttpHandlerConfigInfo > info)
sets a dynamic request handler according to the arguments given
the main namespace for the HttpServer module
string get_exception_string(hash< auto > ex)
returns a multi-line string from the exception hash argument suitable for logging or output on the co...
Private namespace.
Definition: HttpServer.qm.dox.h:1290
Hash for HttpServer options.
Definition: HttpServer.qm.dox.h:345
*LoggerInterface logger
HTTP server logger.
Definition: HttpServer.qm.dox.h:358
bool debug
Debug flag.
Definition: HttpServer.qm.dox.h:350
string name
HTTP server name.
Definition: HttpServer.qm.dox.h:347
hash< auto > hdr
Headers to add in responses.
Definition: HttpServer.qm.dox.h:353