320 class HttpServer::HandlerInfo {
325 AbstractHttpRequestHandler obj;
334 constructor(
string name, AbstractHttpRequestHandler obj,
string path,
bool isregex =
True, *softlist content, *softlist shdr);
337 bool matchContentType(
string ct);
341 int matchRequest(
hash hdr,
int score);
346 class HttpServer::HttpHandlerList {
356 static checkSpecialHeaders(reference sh);
361 setHandler(
string name,
string path,
bool isregex =
True, *softlist content, AbstractHttpRequestHandler obj, *softlist special_headers);
365 *HandlerInfo findHandler(
hash hdr, reference score,
bool final =
False);
376 class HttpServer::DynamicHandlerInfo :
public HttpServer::HandlerInfo {
384 constructor(
string name, AbstractHttpRequestHandler obj,
string path,
bool isregex =
True, *softlist content, *softlist shdr);
389 class HttpServer::DynamicHandlerHelper {
401 constructor(Counter c);
409 class HttpServer::DynamicHttpHandlerList :
public HttpServer::HttpHandlerList {
418 setHandler(
string name,
string path,
bool isregex, *softlist content_type, AbstractHttpRequestHandler obj, *softlist special_headers);
422 removeHandler(
string name);
425 *DynamicHandlerInfo findHandler(
hash hdr, reference score, reference dhh);
467 private hash getAuthHeader();
470 private hash do401(
string msg =
"Authentication is required to access this server");
657 stop(softstring lid);
736 const LP_LOGPARAMS = 1 << 16;
737 const LP_LEVELMASK = LP_LOGPARAMS - 1;
758 "101":
"Switching Protocols",
767 "203":
"Non-Authoritative Information",
769 "205":
"Reset Content",
770 "206":
"Partial Content",
773 "207":
"Multi-Status",
776 "208":
"Already Reported",
782 "300":
"Multiple Choices",
783 "301":
"Moved Permanently",
786 "304":
"Not Modified",
789 "307":
"Temporary Redirect",
792 "400":
"Bad Request",
793 "401":
"Unauthorized",
794 "402":
"Payment Required",
797 "405":
"Method Not Allowed",
798 "406":
"Not Acceptable",
799 "407":
"Proxy Authentication Required",
800 "408":
"Request Timeout",
803 "411":
"Length Required",
804 "412":
"Precondition Failed",
805 "413":
"Request Entity Too Large",
806 "414":
"Request-URI Too Long",
807 "415":
"Unsupported Media Type",
808 "416":
"Requested Range Not Satisfiable",
809 "417":
"Expectation Failed",
812 "418":
"I'm a teapot",
815 "420":
"Enhance Yextern Calm",
818 "422":
"Unprocessable Entity",
824 "424":
"Failed Dependency",
827 "425":
"Unordered Collection",
830 "426":
"Upgrade Required",
833 "428":
"Precondition Required",
836 "429":
"Too Many Requests",
839 "431":
"Request Header Fields Too Large",
842 "500":
"Internal Server Error",
843 "501":
"Not Implemented",
844 "502":
"Bad Gateway",
845 "503":
"Service Unavailable",
846 "504":
"Gateway Timeout",
847 "505":
"HTTP Version Not Supported",
848 "509":
"Bandwidth Limit Exceeded",
851 "510":
"Not Extended",
854 "511":
"Network Authentication Required",
860 "deflate":
"deflate",
863 "x-deflate":
"deflate",
883 Sequence seqSessions();
884 Sequence seqListeners();
886 string httpserverstring;
888 bool stopped =
False;
891 HttpHandlerList handlers();
912 DynamicHttpHandlerList dhandlers();
921 *
string override_encoding;
942 setDefaultTextEncoding(
string enc);
945 string getDefaultTextEncoding();
1015 softlist
addListeners(softstring sock, *
string cert_path, *
string key_path, *
string name,
int family =
AF_UNSPEC);
1197 startConnection(code c);
1206 static final private hash getSSLObjects(
string cert_path, *
string key_path);
1209 final private list addINETListenersIntern(*
string node, softstring service, *
hash sd, *
hash lp, *code logger, *code errorlogger, *code stopc, *
string name,
int family =
AF_UNSPEC);
1213 final private hash noHandlerError(
hash cx,
hash hdr, any body);
1230 *SSLCertificate cert;
1239 bool stopped =
False;
1257 const PollInterval = 1s;
1258 const ListenQueue = 100;
1267 HttpHandlerList handlers();
1270 *HandlerInfo defaultHandler;
1275 constructor(
HttpServer server,
int id, Sequence ss, *
string node, *softstring service, *
Qore::SSLCertificate cert, *
Qore::SSLPrivateKey key, *
hash hi, *code logger, *code errorlogger, *code stopc,
string name,
int family =
AF_UNSPEC);
1278 addHandlers(
hash hi);
1281 setDefaultHandler(
string name);
1311 logResponse(
hash cx,
int code, *data body, *
hash hdr);
1323 private mainThread();
1327 private connectionThread(Socket s);
logError()
called to log error information to the registered error log code
logErrorArgs(softlist args=())
calls the error log function/closure with the given args
logArgs(softlist args=())
calls the log function/closure with the given args
string sprintf(string fmt,...)
hash getListeners()
returns a hash of listener information
hash addListener(softstring sock, *string cert_path, *string key_path, *string name, int family=AF_UNSPEC)
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...
abstract hash handleRequest(hash cx, hash hdr, *data b)
called by the HTTP server to handle incoming HTTP requests
setDebug(bool dbg=True)
turns on or off debugging; when debugging is enabled more verbose error messages are reported ...
string getRealm()
returns the authentication realm as a string
abstract class that all HTTP request handler objects must inherit from
Definition: HttpServer.qm.dox.h:490
*AbstractAuthenticator auth
the optional AbstractAuthenticator for requests to this handler
Definition: HttpServer.qm.dox.h:495
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:731
removeDynamicHandler(string name)
remove dynamic handler
hash lh
hash of listener references; this is to stop all connections associated with a particular listener ...
Definition: HttpServer.qm.dox.h:618
constructor(*AbstractAuthenticator auth)
create the object optionally with the given AbstractAuthenticator
addHandlerToListenerID(softint id, string name, string path, *softlist content_type, AbstractHttpRequestHandler obj, *softlist special_headers, bool isregex=True)
adds a request handler to a listener given the listener's id
destructor()
calls stop() and destroys the object
addHandlerToListener(softstring bind, string name, string path, *softlist content_type, AbstractHttpRequestHandler obj, *softlist special_headers, bool isregex=True)
adds a request handler to a listener given the listener's name or bind address
start(softstring lid, hash cx, hash hdr, Socket s)
called from the HTTP server after the handleRequest() method indicates that a dedicated connection sh...
string getRelativePath(string path)
returns the relative path anchored from the url_root if possible; URI query arguments are stripped of...
setDynamicHandler(string name, string path, *softlist content_type, AbstractHttpRequestHandler obj, *softlist special_headers, bool isregex=True)
sets a dynamic request handler according to the arguments given
const DefaultIdleThreads
default number of idle threads to have waiting for new connections (accross all listeners) ...
Definition: HttpServer.qm.dox.h:868
stopListener(softstring bind)
stops a single listener based on its name or bind address; does not return until all connections on t...
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:743
bool decompress
if POSTed data should be decompressed automatically if there is content-encoding
Definition: HttpServer.qm.dox.h:498
abstract private startImpl(softstring lid, hash cx, hash hdr, Socket s)
called from the HTTP server after the handleRequest() method indicates that a dedicated connection sh...
stop()
stops all listeners; only returns when all connections are closed on all listeners ...
constructor(string url_root, *AbstractAuthenticator auth)
creates the object based on the URL root and optional authenticator
Mutex m()
listener reference hash mutex
private stopImpl()
called from the HTTP server when the socket should be closed due to an external request; the start() ...
static hash make501(string fmt)
creates a hash for an HTTP 501 error response with the response message body as a string ...
constructor(*code logfunc, *code errlogfunc, bool dbg=False, string name=sprintf("Qore-HTTP-Server/%s", HttpServer::Version), hash hdr=("X-Powered-By":"Qore/"+Qore::VersionString))
creates the HttpServer
bool requiresAuthentication()
called to check if the connection requires authentication
abstract base class for external authentication
Definition: HttpServer.qm.dox.h:432
static hash makeResponse(int code, string fmt)
creates a hash for an HTTP response with the response code and the response message body as a formatt...
static hash make400(string fmt)
creates a hash for an HTTP 400 error response with the response message body as a string ...
hash getListenerInfo(softint id)
returns a hash of information about the listener given the listener ID
restoreThreadLocalData(*hash data)
called after handleRequest() with any data returned from saveThreadData()
stop()
called from the HTTP server when the socket should be closed due to an external request; the start() ...
const PollTimeout
default poll timeout in ms
Definition: HttpServer.qm.dox.h:733
softlist addListeners(softstring sock, *string cert_path, *string key_path, *string name, int family=AF_UNSPEC)
adds one or more global listeners according to the bind address
constructor(*AbstractAuthenticator auth)
create the object optionally with the given AbstractAuthenticator
nothing exit(softint rc=0)
hash parse_uri_query(string path)
parses a URI path for a arguments and a method; where the method is the part of the path before the f...
final list addListenersWithHandler(string hname, 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 ...
static *string getLogMessage(hash cx, hash api, reference params, *reference args)
helper method for handling log messages
sendHttpError(HttpListener listener, hash cx, Socket s, int code, string msg, *hash extra_hdrs, *string encoding)
sends an HTTP error message on the socket
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
abstract class that all HTTP dedicated socket handler objects must inherit from
Definition: HttpServer.qm.dox.h:610
abstract class for HTTP request handlers anchored at a specific URL
Definition: HttpServer.qm.dox.h:586
waitStop()
waits for all listeners to be stopped; call after calling HttpServer::stopNoWait() ...
hash handleRequest(hash cx, hash hdr, *data body)
will be called when a request is received that should be directed to the handler
const AIFlags
address info flags
Definition: HttpServer.qm.dox.h:740
bool decompress_to_string
if automatically decompressed POSTed data should be converted to a string (if False, then it will be decompressed to a binary)
Definition: HttpServer.qm.dox.h:501
copy()
throws an exception; these objects do not support copying
const Version
version of the HttpServer's implementation
Definition: HttpServer.qm.dox.h:729
setDefaultHandler(string name, AbstractHttpRequestHandler obj)
sets the default request handler when no other handler can be matched
The HttpServer class implements a multithreaded HTTP server primarily designed for serving RPC-style ...
Definition: HttpServer.qm.dox.h:724
authenticate(string user, string pass="")
called to authenticate a user for a connection
setHandler(string name, string path, *softlist content_type, AbstractHttpRequestHandler obj, *softlist special_headers, bool isregex=True)
sets a request handler according to the arguments given
int getListenerCount()
returns the number of running HTTP listeners
this class implements the listeners for the HttpServer class
Definition: HttpServer.qm.dox.h:1224
log()
called to log information to the registered log code
*hash saveThreadLocalData()
called before handleRequest() any data returned here will be given to restoreThreadLocalData() after ...
list addINETListeners(*string node, softstring service, *string cert_path, *string key_path, *string name, int family=AF_UNSPEC)
adds one or more global listeners according to the bind address
authenticateByIP(string ip, reference user)
called when the connection requires authentication, but no authentication credentials were supplied...
string url_root
root part of URL for matching requests
Definition: HttpServer.qm.dox.h:591
hash getListenerInfoName(string name)
returns a hash of information about the listener given the listener name or bind ID ...
const HttpCodes
map of HTTP result codes and text messages
Definition: HttpServer.qm.dox.h:755
static hash redirect(hash cx, hash hdr, string path)
generates a redirect hash for the given path
*hash authenticateRequest(HttpListener listener, hash hdr, reference cx)
primary method called to authenticate each request
hash lsh
hash of listener stop flags
Definition: HttpServer.qm.dox.h:621
const ContentEncodings
content-encodings supported; this is a hash to simulate a set with O(ln(n)) access times ...
Definition: HttpServer.qm.dox.h:858
int getListenerTID(softint id)
gets the TID of a listener based on its listener ID