238 namespace HttpServer {
251 class HttpServer::HandlerInfo {
268 bool matchContentType(
string ct);
272 int matchRequest(
hash hdr,
int score);
277 class HttpServer::HttpHandlerList {
288 static checkSpecialHeaders(reference sh);
297 *HandlerInfo findHandler(
hash hdr, reference score,
bool finalv =
False, *reference root_path);
308 class HttpServer::DynamicHandlerInfo :
public HttpServer::HandlerInfo {
321 class HttpServer::DynamicHandlerHelper {
333 constructor(Counter n_c);
341 class HttpServer::DynamicHttpHandlerList :
public HttpServer::HttpHandlerList {
354 removeHandler(
string name);
357 *DynamicHandlerInfo findHandler(
hash hdr, reference score, reference dhh, *reference root_path);
398 "deflate":
"deflate",
401 "x-deflate":
"deflate",
446 Sequence seqSessions();
447 Sequence seqListeners();
449 bool stopped =
False;
452 HttpHandlerList handlers();
473 DynamicHttpHandlerList dhandlers();
482 *
string override_encoding;
484 string http_server_string;
508 setDefaultTextEncoding(
string enc);
511 string getDefaultTextEncoding();
592 hash addListener(softstring sock, *
string cert_path, *
string key_path, *
string name,
int family =
AF_UNSPEC, *
string pwd);
612 softlist
addListeners(softstring sock, *
string cert_path, *
string key_path, *
string name,
int family =
AF_UNSPEC, *
string pwd);
631 list addINETListeners(*
string node, softstring service, *
string cert_path, *
string key_path, *
string name,
int family =
AF_UNSPEC, *
string pwd);
841 startConnection(code c);
867 static final private hash getSSLObjects(
string cert_path, *
string key_path, *
string pwd);
870 final private list addINETListenersIntern(*
string node, softstring service, *
hash sd, *
hash lp, *code logger, *code errorlogger, *code stopc, *
string name,
int family =
AF_UNSPEC);
874 final private hash noHandlerError(
hash cx,
hash hdr, any body);
879 final handleRequest(
HttpListener listener, Socket s, reference cx,
hash hdr,
hash hh, *data body,
bool head =
False, HttpPersistentHandlerInfo phi);
889 class HttpServer::HttpPersistentHandlerInfo {
893 *DynamicHandlerHelper dhh;
917 *SSLCertificate cert;
926 bool stopped =
False;
945 bool log_recv_headers =
False;
948 bool log_recv_body =
False;
951 bool log_send_headers =
False;
954 bool log_send_body =
False;
956 const PollInterval = 1s;
957 const ListenQueue = 100;
966 HttpHandlerList handlers();
969 *HandlerInfo defaultHandler;
974 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);
977 addHandlers(
hash hi);
980 setDefaultHandler(
string name);
989 logRecvHeaders(softbool flag =
True);
992 logRecvBody(softbool flag =
True);
995 logSendHeaders(softbool flag =
True);
998 logSendBody(softbool flag =
True);
1001 hash getLogOptions();
1019 any removeUserThreadContext(*
string k);
1022 addUserThreadContext(
hash uctx);
1031 logResponse(
hash cx,
int code, *data body, *
hash hdr);
1040 logError(
string fmt);
1043 private mainThread();
1047 private 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
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:369
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:421
const DefaultIdleThreads
default number of idle threads to have waiting for new connections (accross all listeners) ...
Definition: HttpServer.qm.dox.h:406
stopListener(softstring bind)
stops a single listener based on its name or bind address; does not return until all connections on t...
private setListenerLogOptionsUnlocked(softstring id, int code)
turns on or off header and body logging options for the given listener according to the option code ...
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:381
stop()
stops all listeners; only returns when all connections are closed on all listeners ...
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:430
const PollTimeout
default poll timeout in ms
Definition: HttpServer.qm.dox.h:371
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:424
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
const CompressionThreshold
default threadhold for data compressions; transfers smaller than this size will not be compressed ...
Definition: HttpServer.qm.dox.h:409
waitStop()
waits for all listeners to be stopped; call after calling HttpServer::stopNoWait() ...
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
static nothing setReplyHeaders(Socket s, hash cx, reference rv)
helper method to set HTTP response headers
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:378
copy()
throws an exception; these objects do not support copying
const Version
version of the HttpServer's implementation
Definition: HttpServer.qm.dox.h:367
The HttpServer class implements a multithreaded HTTP server.
Definition: HttpServer.qm.dox.h:362
int getListenerCount()
returns the number of running HTTP listeners
this class implements the listeners for the HttpServer class
Definition: HttpServer.qm.dox.h:911
private int getListenerIdFromBindUnlocked(string bind)
returns the listener ID from the bind name or throws an exception if not valid
listenerStarted(int id, hash sinfo)
called from listener when the actual listener thread is running
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:393
const LLO_SEND_HEADERS
listener log option: log send headers
Definition: HttpServer.qm.dox.h:427
private int getListenerLogOptionsUnlocked(softstring id)
returns header and body logging options for the given listener as a binary-or'ed value of listener lo...
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:396
int getListenerTID(softint id)
gets the TID of a listener based on its listener ID