388 const PollTimeout = 250ms;
395 const AIFlags = AI_PASSIVE | AI_ADDRCONFIG;
398 const HttpMethods = ...;
405 const ContentEncodings = ...;
409 const DefaultIdleThreads = 10;
412 const CompressionThreshold = 1024;
424 const LLO_RECV_HEADERS = (1 << 0);
427 const LLO_RECV_BODY = (1 << 1);
430 const LLO_SEND_HEADERS = (1 << 2);
433 const LLO_SEND_BODY = (1 << 3);
437 const DefaultTtl = 75s;
450 Sequence seqSessions();
451 Sequence seqListeners();
453 bool stopped = False;
456 HttpHandlerList handlers();
459 hash<auto> defaultHandler;
462 hash<string, HttpListener> listeners;
465 hash<string, int> smap;
468 hash<string, int> nmap;
477 DynamicHttpHandlerList dhandlers();
480 ThreadPool threadPool(-1, DefaultIdleThreads);
488 *
string override_encoding;
491 string http_server_string;
494 hash<string, bool> http_methods = HttpMethods;
497 *LoggerInterface logger;
500 bool protect_last_listener = False;
503 date ttl = DefaultTtl;
564 setDefaultTextEncoding(
string enc);
567 string getDefaultTextEncoding();
592 final list<hash<auto>>
addListeners(
string bind, hash<HttpListenerOptionInfo> info, *reference<hash<string, string>> errmap);
609 final list<hash<auto>>
addListeners(hash<HttpListenerOptionInfo> info, *reference<hash<string, string>> errmap);
945 sendHttpError(
HttpListener listener, hash<auto> cx, Socket s,
int code, *data msg, *InputStream chunked_msg, *hash<auto> extra_hdrs, *
string encoding,
bool head);
987 startConnection(code c);
1024 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);
1029 final HttpListener addListenerIntern(hash<HttpListenerOptionInfo> info);
1035 final list<hash<auto>> addINETListenersIntern(hash<HttpListenerOptionInfo> info, *reference<hash<string, string>> errmap);
1041 final hash<HttpResponseInfo> noHandlerError(hash<auto> cx, hash<auto> hdr,
auto body);
1047 final handleRequest(
HttpListener listener, Socket s, reference<hash<auto>> cx, hash<auto> hdr,
bool head = False, HttpPersistentHandlerInfo phi, hash<auto> info, reference<bool> dedicated, reference<bool> dedicated_external);
1057 doResponse(
HttpListener listener, Socket s, hash<auto> cx, hash rv);
1063class HttpPersistentHandlerInfo {
1066 *DynamicHandlerHelper dhh;
1089 *hash<HttpListenerOptionInfo> opts;
1103 bool stopped = False;
1107 hash<string, AbstractHttpSocketHandlerInterface> shh;
1121 bool log_recv_headers = False;
1124 bool log_recv_body = False;
1127 bool log_send_headers = False;
1130 bool log_send_body = False;
1144 const PollInterval = 250ms;
1145 const ListenQueue = 100;
1146 const BodyLogLimit = 40;
1149 int handler_ref_cnt = 0;
1152 HttpHandlerList handlers();
1164 *HandlerInfo defaultHandler;
1204 setDefaultHandler(
string name);
1207 *HandlerInfo findHandler(hash<auto> hdr, reference<int> score,
bool finalv = False, *reference<string> root_path);
1219 hash getListenerSocketInfo();
1228 logRecvHeaders(softbool flag = True);
1231 logRecvBody(softbool flag = True);
1234 logSendHeaders(softbool flag = True);
1237 logSendBody(softbool flag = True);
1240 doLogRecvBody(*data body, hash<auto> cx, hash<auto> hdr, hash<auto> info);
1243 hash<auto> getLogOptions();
1258 hash<auto> getInfo();
1267 softlist<string> getSslVerifyModeList();
1271 auto removeUserThreadContext(*
string k);
1274 addUserThreadContext(hash<auto> uctx);
1283 logResponse(hash<auto> cx,
int code, *data body, *hash<auto> hdr);
1286 logResponse(hash<auto> cx,
int code, InputStream body, *hash<auto> hdr);
1289 logResponse(hash<auto> cx, hash<auto> rv);
1292 log(
string fmt, ...);
1295 logError(
string fmt, ...);
1305 connectionThread(Socket s);
1312 removeExternalDedicatedSocket(softstring
id);
1315 removeDedicatedSocket(softstring
id, *
bool managed_externally);
1331 *hash<string, bool> content_type_map;
1332 *list<string> special_header_list;
1337 constructor(
string name, hash<HttpHandlerConfigInfo> info);
1340 bool matchContentType(
string ct);
1344 int matchRequest(hash<auto> hdr,
int score);
1352class HttpHandlerList {
1355 hash<string, HandlerInfo> handlers;
1370 setHandler(
string name, hash<HttpHandlerConfigInfo> info);
1377 removeHandler(
string handler_name);
1388 *HandlerInfo findHandler(hash<auto> hdr, reference<int> score,
bool finalv = False, *reference<string> root_path);
1399class DynamicHandlerInfo :
public HandlerInfo {
1404 constructor(
string name, hash<HttpHandlerConfigInfo> info) ;
1409class DynamicHandlerHelper {
1419 constructor(Counter n_c);
1427class DynamicHttpHandlerList :
public HttpHandlerList {
1434 hash<string, bool> disable_map;
1439 setHandler(
string name, hash<HttpHandlerConfigInfo> info);
1445 removeHandler(
string name, *
bool force_immediate);
1451 disableHandler(
string name);
1454 *DynamicHandlerInfo findHandler(hash<auto> hdr, reference<int> score, reference<DynamicHandlerHelper> dhh, *reference<string> root_path);
1458class HttpServerCallbackAppender :
public LoggerAppenderWithLayout {
1466 constructor(code logfunc) ;
1469 processEventImpl(
int type,
auto params);
this class implements the listeners for the HttpServer class
Definition HttpServer.qm.dox.h:1082
removeHandler(HttpServer::AbstractHttpRequestHandler handler)
const SslVerifyMap
map for converting ssl verify flags to strings
Definition HttpServer.qm.dox.h:1155
constructor(HttpServer server, string name, int id, Sequence ss, *hash< HttpListenerOptionInfo > opts)
creates the object with the given parameters
int lock_waiting
thread waiting on lock
Definition HttpServer.qm.dox.h:1142
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:1133
int ssl_verify_flags
SSL verify flags.
Definition HttpServer.qm.dox.h:1136
bool ssl_accept_all_certs
accept all certificates
Definition HttpServer.qm.dox.h:1139
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:1113
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:386
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
clearContextInfo()
This method is called after each request to clear context info so that it does not leak into other re...
setTtl(date ttl)
Sets the connection TTL value.
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
date getTtl()
Returns the TTL value.
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
const DefaultTtl
Default connection time-to-live.
Definition HttpServer.qm.dox.h:437
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.
log(string fmt,...)
called to log information to the registered log code
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
logError(string fmt,...)
called to log error information to the registered error log code
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:402
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
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:1321
Hash for HttpServer options.
Definition HttpServer.qm.dox.h:357
*LoggerInterface logger
HTTP server logger.
Definition HttpServer.qm.dox.h:376
bool protect_last_listener
Do not allow the last listener to be stopped.
Definition HttpServer.qm.dox.h:365
bool debug
Debug flag.
Definition HttpServer.qm.dox.h:362
string name
HTTP server name.
Definition HttpServer.qm.dox.h:359
hash< auto > hdr
Headers to add in responses.
Definition HttpServer.qm.dox.h:368
date ttl
Idle disconnect time; the default is 75 seconds.
Definition HttpServer.qm.dox.h:373