375 const PollTimeout = 250ms;
382 const AIFlags = AI_PASSIVE | AI_ADDRCONFIG;
385 const HttpMethods = {
401 const ContentEncodings = {
403 "deflate":
"deflate",
406 "x-deflate":
"deflate",
411 const DefaultIdleThreads = 10;
414 const CompressionThreshold = 1024;
426 const LLO_RECV_HEADERS = (1 << 0);
429 const LLO_RECV_BODY = (1 << 1);
432 const LLO_SEND_HEADERS = (1 << 2);
435 const LLO_SEND_BODY = (1 << 3);
449 Sequence seqSessions();
450 Sequence seqListeners();
452 bool stopped = False;
455 HttpHandlerList handlers();
458 hash<auto> defaultHandler;
461 hash<string, HttpListener> listeners;
464 hash<string, int> smap;
467 hash<string, int> nmap;
476 DynamicHttpHandlerList dhandlers();
479 ThreadPool threadPool(-1, DefaultIdleThreads);
487 *
string override_encoding;
490 string http_server_string;
493 hash<string, bool> http_methods = HttpMethods;
496 *LoggerInterface logger;
549 setDefaultTextEncoding(
string enc);
552 string getDefaultTextEncoding();
577 final list<hash<auto>>
addListeners(
string bind, hash<HttpListenerOptionInfo> info, *reference<hash<string, string>> errmap);
594 final list<hash<auto>>
addListeners(hash<HttpListenerOptionInfo> info, *reference<hash<string, string>> errmap);
930 sendHttpError(
HttpListener listener, hash<auto> cx, Socket s,
int code, *data msg, *InputStream chunked_msg, *hash<auto> extra_hdrs, *
string encoding,
bool head);
972 startConnection(code c);
1009 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);
1014 final HttpListener addListenerIntern(hash<HttpListenerOptionInfo> info);
1020 final list<hash<auto>> addINETListenersIntern(hash<HttpListenerOptionInfo> info, *reference<hash<string, string>> errmap);
1026 final hash<HttpResponseInfo> noHandlerError(hash<auto> cx, hash<auto> hdr,
auto body);
1032 final handleRequest(
HttpListener listener, Socket s, reference<hash<auto>> cx, hash<auto> hdr,
bool head = False, HttpPersistentHandlerInfo phi, hash<auto> info, reference<bool> dedicated);
1042 doResponse(
HttpListener listener, Socket s, hash<auto> cx, hash rv);
1048class HttpPersistentHandlerInfo {
1051 *DynamicHandlerHelper dhh;
1074 *hash<HttpListenerOptionInfo> opts;
1088 bool stopped = False;
1092 hash<string, AbstractHttpSocketHandlerInterface> shh;
1106 bool log_recv_headers = False;
1109 bool log_recv_body = False;
1112 bool log_send_headers = False;
1115 bool log_send_body = False;
1126 const PollInterval = 250ms;
1127 const ListenQueue = 100;
1128 const BodyLogLimit = 40;
1131 int handler_ref_cnt = 0;
1134 HttpHandlerList handlers();
1138 SSL_VERIFY_PEER:
"SSL_VERIFY_PEER",
1139 SSL_VERIFY_FAIL_IF_NO_PEER_CERT:
"SSL_VERIFY_FAIL_IF_NO_PEER_CERT",
1140 SSL_VERIFY_CLIENT_ONCE:
"SSL_VERIFY_CLIENT_ONCE",
1149 *HandlerInfo defaultHandler;
1189 setDefaultHandler(
string name);
1192 *HandlerInfo findHandler(hash<auto> hdr, reference<int> score,
bool finalv = False, *reference<string> root_path);
1204 hash getListenerSocketInfo();
1213 logRecvHeaders(softbool flag = True);
1216 logRecvBody(softbool flag = True);
1219 logSendHeaders(softbool flag = True);
1222 logSendBody(softbool flag = True);
1225 doLogRecvBody(*data body, hash<auto> cx, hash<auto> hdr, hash<auto> info);
1228 hash<auto> getLogOptions();
1243 hash<auto> getInfo();
1252 softlist<string> getSslVerifyModeList();
1256 auto removeUserThreadContext(*
string k);
1259 addUserThreadContext(hash<auto> uctx);
1268 logResponse(hash<auto> cx,
int code, *data body, *hash<auto> hdr);
1271 logResponse(hash<auto> cx,
int code, InputStream body, *hash<auto> hdr);
1274 logResponse(hash<auto> cx, hash<auto> rv);
1277 log(
string fmt, ...);
1280 logError(
string fmt, ...);
1290 connectionThread(Socket s);
1313 *hash<string, bool> content_type_map;
1314 *list<string> special_header_list;
1319 constructor(
string name, hash<HttpHandlerConfigInfo> info);
1322 bool matchContentType(
string ct);
1326 int matchRequest(hash<auto> hdr,
int score);
1334class HttpHandlerList {
1337 hash<string, HandlerInfo> handlers;
1352 setHandler(
string name, hash<HttpHandlerConfigInfo> info);
1359 removeHandler(
string handler_name);
1370 *HandlerInfo findHandler(hash<auto> hdr, reference<int> score,
bool finalv = False, *reference<string> root_path);
1381class DynamicHandlerInfo :
public HandlerInfo {
1386 constructor(
string name, hash<HttpHandlerConfigInfo> info) ;
1391class DynamicHandlerHelper {
1401 constructor(Counter n_c);
1409class DynamicHttpHandlerList :
public HttpHandlerList {
1416 hash<string, bool> disable_map;
1421 setHandler(
string name, hash<HttpHandlerConfigInfo> info);
1427 removeHandler(
string name, *
bool force_immediate);
1433 disableHandler(
string name);
1436 *DynamicHandlerInfo findHandler(hash<auto> hdr, reference<int> score, reference<DynamicHandlerHelper> dhh, *reference<string> root_path);
1440class HttpServerCallbackAppender :
public LoggerAppenderWithLayout {
1448 constructor(code logfunc) ;
1451 processEventImpl(
int type,
auto params);
this class implements the listeners for the HttpServer class
Definition: HttpServer.qm.dox.h:1067
removeHandler(HttpServer::AbstractHttpRequestHandler handler)
const SslVerifyMap
map for converting ssl verify flags to strings
Definition: HttpServer.qm.dox.h:1137
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:1118
int ssl_verify_flags
SSL verify flags.
Definition: HttpServer.qm.dox.h:1121
bool ssl_accept_all_certs
accept all certificates
Definition: HttpServer.qm.dox.h:1124
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:1098
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:373
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...
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
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:398
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:1303
Hash for HttpServer options.
Definition: HttpServer.qm.dox.h:350
*LoggerInterface logger
HTTP server logger.
Definition: HttpServer.qm.dox.h:363
bool debug
Debug flag.
Definition: HttpServer.qm.dox.h:355
string name
HTTP server name.
Definition: HttpServer.qm.dox.h:352
hash< auto > hdr
Headers to add in responses.
Definition: HttpServer.qm.dox.h:358