392 const PollTimeout = 250ms;
399 const AIFlags = AI_PASSIVE | AI_ADDRCONFIG;
402 const HttpMethods = ...;
409 const ContentEncodings = ...;
413 const DefaultIdleThreads = 10;
416 const CompressionThreshold = 1024;
428 const LLO_RECV_HEADERS = (1 << 0);
431 const LLO_RECV_BODY = (1 << 1);
434 const LLO_SEND_HEADERS = (1 << 2);
437 const LLO_SEND_BODY = (1 << 3);
441 const DefaultTtl = 75s;
454 Sequence seqSessions();
455 Sequence seqListeners();
457 bool stopped = False;
460 HttpHandlerList handlers();
463 hash<auto> defaultHandler;
466 hash<string, HttpListener> listeners;
469 hash<string, int> smap;
472 hash<string, int> nmap;
481 DynamicHttpHandlerList dhandlers();
484 ThreadPool threadPool(-1, DefaultIdleThreads);
492 *
string override_encoding;
495 string http_server_string;
498 hash<string, bool> http_methods = HttpMethods;
501 *LoggerInterface logger;
504 bool protect_last_listener = False;
507 date ttl = DefaultTtl;
568 setDefaultTextEncoding(
string enc);
571 string getDefaultTextEncoding();
596 final list<hash<auto>>
addListeners(
string bind, hash<HttpListenerOptionInfo> info, *reference<hash<string, string>> errmap);
613 final list<hash<auto>>
addListeners(hash<HttpListenerOptionInfo> info, *reference<hash<string, string>> errmap);
949 sendHttpError(
HttpListener listener, hash<auto> cx, Socket s,
int status_code, *data msg, *InputStream chunked_msg, *hash<auto> extra_hdrs, *
string encoding,
bool head);
991 startConnection(code c);
1028 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);
1033 final HttpListener addListenerIntern(hash<HttpListenerOptionInfo> info);
1039 final list<hash<auto>> addINETListenersIntern(hash<HttpListenerOptionInfo> info, *reference<hash<string, string>> errmap);
1045 final hash<HttpResponseInfo> noHandlerError(hash<auto> cx, hash<auto> hdr,
auto body);
1052 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);
1062 doResponse(
HttpListener listener, Socket s, hash<auto> cx, hash rv);
1068class HttpPersistentHandlerInfo {
1071 *DynamicHandlerHelper dhh;
1094 *hash<HttpListenerOptionInfo> opts;
1108 bool stopped = False;
1112 hash<string, AbstractHttpSocketHandlerInterface> shh;
1126 bool log_recv_headers = False;
1129 bool log_recv_body = False;
1132 bool log_send_headers = False;
1135 bool log_send_body = False;
1149 const PollInterval = 250ms;
1150 const ListenQueue = 100;
1151 const BodyLogLimit = 40;
1154 int handler_ref_cnt = 0;
1157 HttpHandlerList handlers();
1169 *HandlerInfo defaultHandler;
1209 setDefaultHandler(
string name);
1212 *HandlerInfo findHandler(hash<auto> hdr, reference<int> score,
bool finalv = False, *reference<string> root_path);
1224 hash getListenerSocketInfo();
1233 logRecvHeaders(softbool flag = True);
1236 logRecvBody(softbool flag = True);
1239 logSendHeaders(softbool flag = True);
1242 logSendBody(softbool flag = True);
1245 doLogRecvBody(*data body, hash<auto> cx, hash<auto> hdr, hash<auto> info);
1248 hash<auto> getLogOptions();
1263 hash<auto> getInfo();
1272 softlist<string> getSslVerifyModeList();
1276 auto removeUserThreadContext(*
string k);
1279 addUserThreadContext(hash<auto> uctx);
1288 string getResponseLogString(hash<auto> cx,
int status_code, *data body, *hash<auto> hdr);
1291 logResponse(hash<auto> cx,
int status_code, *data body, *hash<auto> hdr);
1294 logResponse(hash<auto> cx,
int code, InputStream body, *hash<auto> hdr);
1297 logResponse(hash<auto> cx, hash<auto> rv);
1301 logResponseError(hash<auto> cx, hash<auto> rv, hash<ExceptionInfo> ex);
1304 log(
string fmt, ...);
1307 logError(
string fmt, ...);
1317 connectionThread(Socket s);
1324 removeExternalDedicatedSocket(softstring
id);
1327 removeDedicatedSocket(softstring
id, *
bool managed_externally);
1343 *hash<string, bool> content_type_map;
1344 *list<string> special_header_list;
1349 constructor(
string name, hash<HttpHandlerConfigInfo> info);
1352 bool matchContentType(
string ct);
1356 int matchRequest(hash<auto> hdr,
int score);
1364class HttpHandlerList {
1367 hash<string, HandlerInfo> handlers;
1382 setHandler(
string name, hash<HttpHandlerConfigInfo> info);
1389 removeHandler(
string handler_name);
1400 *HandlerInfo findHandler(hash<auto> hdr, reference<int> score,
bool finalv = False, *reference<string> root_path);
1411class DynamicHandlerInfo :
public HandlerInfo {
1416 constructor(
string name, hash<HttpHandlerConfigInfo> info) ;
1421class DynamicHandlerHelper {
1431 constructor(Counter n_c);
1439class DynamicHttpHandlerList :
public HttpHandlerList {
1446 hash<string, bool> disable_map;
1451 setHandler(
string name, hash<HttpHandlerConfigInfo> info);
1457 removeHandler(
string name, *
bool force_immediate);
1463 disableHandler(
string name);
1466 *DynamicHandlerInfo findHandler(hash<auto> hdr, reference<int> score, reference<DynamicHandlerHelper> dhh, *reference<string> root_path);
1470class HttpServerCallbackAppender :
public LoggerAppenderWithLayout {
1478 constructor(code logfunc) ;
1481 processEventImpl(
int type,
auto params);
this class implements the listeners for the HttpServer class
Definition HttpServer.qm.dox.h:1087
removeHandler(HttpServer::AbstractHttpRequestHandler handler)
const SslVerifyMap
map for converting ssl verify flags to strings
Definition HttpServer.qm.dox.h:1160
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:1147
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:1138
int ssl_verify_flags
SSL verify flags.
Definition HttpServer.qm.dox.h:1141
bool ssl_accept_all_certs
accept all certificates
Definition HttpServer.qm.dox.h:1144
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:1118
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:390
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:441
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:406
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
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
sendHttpError(HttpListener listener, hash< auto > cx, Socket s, int status_code, *data msg, *InputStream chunked_msg, *hash< auto > extra_hdrs, *string encoding, bool head)
sends an HTTP error message on the socket
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:1333
Hash for HttpServer options.
Definition HttpServer.qm.dox.h:361
*LoggerInterface logger
HTTP server logger.
Definition HttpServer.qm.dox.h:380
bool protect_last_listener
Do not allow the last listener to be stopped.
Definition HttpServer.qm.dox.h:369
bool debug
Debug flag.
Definition HttpServer.qm.dox.h:366
string name
HTTP server name.
Definition HttpServer.qm.dox.h:363
hash< auto > hdr
Headers to add in responses.
Definition HttpServer.qm.dox.h:372
date ttl
Idle disconnect time; the default is 75 seconds.
Definition HttpServer.qm.dox.h:377