256 class HttpServer::HandlerInfo {
261 AbstractHttpRequestHandler obj;
270 constructor(
string name, AbstractHttpRequestHandler obj,
string path,
bool isregex =
True, *softlist content, *softlist shdr);
273 bool matchContentType(
string ct);
277 int matchRequest(
hash hdr,
int score);
282 class HttpServer::HttpHandlerList {
292 static checkSpecialHeaders(reference sh);
297 setHandler(
string name,
string path,
bool isregex =
True, *softlist content, AbstractHttpRequestHandler obj, *softlist special_headers);
301 *HandlerInfo findHandler(
hash hdr, reference score,
bool final =
False);
312 class HttpServer::DynamicHandlerInfo :
public HttpServer::HandlerInfo {
320 constructor(
string name, AbstractHttpRequestHandler obj,
string path,
bool isregex =
True, *softlist content, *softlist shdr);
325 class HttpServer::DynamicHandlerHelper {
337 constructor(Counter c);
345 class HttpServer::DynamicHttpHandlerList :
public HttpServer::HttpHandlerList {
354 setHandler(
string name,
string path,
bool isregex, *softlist content_type, AbstractHttpRequestHandler obj, *softlist special_headers);
358 removeHandler(
string name);
361 *DynamicHandlerInfo findHandler(
hash hdr, reference score, reference dhh);
403 private hash getAuthHeader();
406 private hash do401(
string msg =
"Authentication is required to access this server");
579 hash handleRequest();
614 private logChunk(
bool send,
int size);
861 stop(softstring lid);
940 const LP_LOGPARAMS = 1 << 16;
941 const LP_LEVELMASK = LP_LOGPARAMS - 1;
962 "101":
"Switching Protocols",
971 "203":
"Non-Authoritative Information",
973 "205":
"Reset Content",
974 "206":
"Partial Content",
977 "207":
"Multi-Status",
980 "208":
"Already Reported",
986 "300":
"Multiple Choices",
987 "301":
"Moved Permanently",
990 "304":
"Not Modified",
993 "307":
"Temporary Redirect",
996 "400":
"Bad Request",
997 "401":
"Unauthorized",
998 "402":
"Payment Required",
1001 "405":
"Method Not Allowed",
1002 "406":
"Not Acceptable",
1003 "407":
"Proxy Authentication Required",
1004 "408":
"Request Timeout",
1007 "411":
"Length Required",
1008 "412":
"Precondition Failed",
1009 "413":
"Request Entity Too Large",
1010 "414":
"Request-URI Too Long",
1011 "415":
"Unsupported Media Type",
1012 "416":
"Requested Range Not Satisfiable",
1013 "417":
"Expectation Failed",
1016 "418":
"I'm a teapot",
1019 "420":
"Enhance Yextern Calm",
1022 "422":
"Unprocessable Entity",
1028 "424":
"Failed Dependency",
1031 "425":
"Unordered Collection",
1034 "426":
"Upgrade Required",
1037 "428":
"Precondition Required",
1040 "429":
"Too Many Requests",
1043 "431":
"Request Header Fields Too Large",
1046 "500":
"Internal Server Error",
1047 "501":
"Not Implemented",
1048 "502":
"Bad Gateway",
1049 "503":
"Service Unavailable",
1050 "504":
"Gateway Timeout",
1051 "505":
"HTTP Version Not Supported",
1052 "509":
"Bandwidth Limit Exceeded",
1055 "510":
"Not Extended",
1058 "511":
"Network Authentication Required",
1064 "deflate":
"deflate",
1067 "x-deflate":
"deflate",
1090 Sequence seqSessions();
1091 Sequence seqListeners();
1093 bool stopped =
False;
1096 HttpHandlerList handlers();
1099 hash defaultHandler;
1117 DynamicHttpHandlerList dhandlers();
1126 *
string override_encoding;
1128 static string HttpServerString;
1152 setDefaultTextEncoding(
string enc);
1155 string getDefaultTextEncoding();
1208 hash addListener(softstring sock, *
string cert_path, *
string key_path, *
string name,
int family =
AF_UNSPEC, *
string pwd);
1228 softlist
addListeners(softstring sock, *
string cert_path, *
string key_path, *
string name,
int family =
AF_UNSPEC, *
string pwd);
1247 list addINETListeners(*
string node, softstring service, *
string cert_path, *
string key_path, *
string name,
int family =
AF_UNSPEC, *
string pwd);
1411 startConnection(code c);
1423 static final private hash getSSLObjects(
string cert_path, *
string key_path, *
string pwd);
1426 final private list addINETListenersIntern(*
string node, softstring service, *
hash sd, *
hash lp, *code logger, *code errorlogger, *code stopc, *
string name,
int family =
AF_UNSPEC);
1430 final private hash noHandlerError(
hash cx,
hash hdr, any body);
1435 final handleRequest(
HttpListener listener, Socket s, reference cx,
hash hdr,
hash hh, *data body,
bool head =
False, HttpPersistentHandlerInfo phi);
1445 class HttpServer::HttpPersistentHandlerInfo {
1449 *DynamicHandlerHelper dhh;
1471 *SSLCertificate cert;
1480 bool stopped =
False;
1498 const PollInterval = 1s;
1499 const ListenQueue = 100;
1508 HttpHandlerList handlers();
1511 *HandlerInfo defaultHandler;
1516 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);
1519 addHandlers(
hash hi);
1522 setDefaultHandler(
string name);
1546 any removeUserThreadContext(
string k);
1549 addUserThreadContext(
hash uctx);
1558 logResponse(
hash cx,
int code, *data body, *
hash hdr);
1570 private mainThread();
1574 private connectionThread(Socket s);
*hash authenticateRequest(HttpListener listener, hash hdr, reference cx)
primary method called to authenticate each request
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
constructor(HttpListener listener, AbstractHttpRequestHandler handler, Socket s, hash cx, hash hdr, any body)
creates the object with the given attributes
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
any send()
this method provides the callback method for sending chunked data by calling sendImpl() ...
abstract nothing recvImpl(hash v)
abstract callback method for receiving chunked data
string sprintf(string fmt,...)
hash getListeners()
returns a hash of listener information
hash hdr
a hash of request headers
Definition: HttpServer.qm.dox.h:569
private nothing recvImpl(hash v)
abstract callback method for receiving chunked data
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 class for streaming HTTP chunked requests/responses
Definition: HttpServer.qm.dox.h:552
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:661
class providing automatic authentication for all requests
Definition: HttpServer.qm.dox.h:424
*AbstractAuthenticator auth
the optional AbstractAuthenticator for requests to this handler
Definition: HttpServer.qm.dox.h:666
static string getURLFromBind(softstring bind, *string host)
returns a complete URL from a bind address
constructor(hash cx)
creates the object with the given arguments
const ReadTimeout
default read timeout in ms
Definition: HttpServer.qm.dox.h:935
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:822
*hash ex
if an exception is raised in a callback then the exception hash is saved here
Definition: HttpServer.qm.dox.h:457
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...
bool persistent
persistent connection flag
Definition: HttpServer.qm.dox.h:678
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
*data getMessageBody(Socket s, hash hdr, *data body, bool decode=True)
optionally retrieves and post-processes any message body
const DefaultIdleThreads
default number of idle threads to have waiting for new connections (accross all listeners) ...
Definition: HttpServer.qm.dox.h:1072
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...
private hash sendResponse()
called to either create the response hash or send a chunked response directly
const HttpMethods
supported HTTP methods
Definition: HttpServer.qm.dox.h:947
AbstractHttpRequestHandler handler
the request handler for the request
Definition: HttpServer.qm.dox.h:563
nothing recv(hash v)
this method provides the callback method for receiving chunked data by calling recvImpl() ...
bool decompress
if POSTed data should be decompressed automatically if there is content-encoding
Definition: HttpServer.qm.dox.h:669
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...
hash cx
call context hash
Definition: HttpServer.qm.dox.h:455
private hash getResponseHeaderMessageImpl()
this method should return the response message description hash
stop()
stops all listeners; only returns when all connections are closed on all listeners ...
bool stream
if the handler supports streaming requests/responses with chunked data
Definition: HttpServer.qm.dox.h:675
constructor(*AbstractAuthenticator auth, softbool stream=False)
create the object optionally with the given AbstractAuthenticator
constructor(string url_root, *AbstractAuthenticator auth)
creates the object based on the URL root and optional authenticator
Mutex m()
listener reference hash mutex
abstract class for embedded objects serving streaming requests
Definition: HttpServer.qm.dox.h:446
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:368
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()
private nothing recv(hash v)
this is the primary callback for receiving chunked data; data will be logged, and then recvImpl() is ...
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:937
hash cx
the call context variable
Definition: HttpServer.qm.dox.h:567
Socket s
the Socket object for the response
Definition: HttpServer.qm.dox.h:565
private any sendImpl()
abstract callback method for sending chunked data
hash parse_uri_query(string path, bool trans=True)
parses a URI path for a arguments and a method; where the method is the part of the path before the f...
constructor(*AbstractAuthenticator auth)
create the object optionally with the given AbstractAuthenticator
nothing exit(softint rc=0)
static binary encodeBody(string ce, data body)
encodes a message body with content-encoding
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 getHttpServerVersionString()
returns the HTTP server version string
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
private AbstractStreamRequest getStreamRequestImpl(HttpListener listener, Socket s, hash cx, hash hdr, *data body)
returns the AbstractStreamRequest object for handling chunked requests
abstract any sendImpl()
abstract callback method for sending chunked data
const CompressionThreshold
default threadhold for data compressions; transfers smaller than this size will not be compressed ...
Definition: HttpServer.qm.dox.h:1075
abstract hash getResponseHeaderMessageImpl()
this method should return the response message description hash
softlist addListeners(softstring sock, *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
private any send()
this is the primary callback for sending chunked responses; first sendImpl() is called to get the raw...
abstract class that all HTTP dedicated socket handler objects must inherit from
Definition: HttpServer.qm.dox.h:814
abstract class for HTTP request handlers anchored at a specific URL
Definition: HttpServer.qm.dox.h:790
waitStop()
waits for all listeners to be stopped; call after calling HttpServer::stopNoWait() ...
static data decodeBody(string ce, binary body, *string enc)
decodes a message body with content-encoding
hash handleRequest(hash cx, hash hdr, *data body)
will be called when a request is received that should be directed to the handler
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:944
private hash getResponseHeaderMessage()
this method returns the response message description hash by calling getResponseHeaderMessageImpl() ...
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:672
copy()
throws an exception; these objects do not support copying
const Version
version of the HttpServer's implementation
Definition: HttpServer.qm.dox.h:933
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:928
authenticate(string user, string pass="")
called to authenticate a user for a connection
the main namespace for the HttpServer module
Definition: HttpServer.qm.dox.h:231
HttpListener listener
the listener servicing the request for logging purposes
Definition: HttpServer.qm.dox.h:561
hash getResponseHeaderMessage()
this method returns the response message description hash by calling getResponseHeaderMessageImpl() ...
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:1465
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 ...
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:795
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:959
nothing persistentClosed()
called externally when a persistent connection is closed
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:825
any body
any message body given in a non-chunked request; could already be deserialized
Definition: HttpServer.qm.dox.h:571
private nothing checkPersistent(hash cx, hash hdr)
this method will throw an exception if a persistent connection cannot be granted
const ContentEncodings
content-encodings supported; this is a hash to simulate a set with O(ln(n)) access times ...
Definition: HttpServer.qm.dox.h:1062
int getListenerTID(softint id)
gets the TID of a listener based on its listener ID