All Classes Namespaces Functions Variables Groups Pages
HttpServer.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// @file HttpServer.qm HTTP multi-threaded server module definition
/* HttpServer.qm Copyright (C) 2012 - 2014 David Nichols
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// need mime definitions
/* Version History
* 2013-03-05 v0.3.7: David Nichols <david@qore.org>
+ fixed a bug in parsing arguments in parse_uri_query()
+ updated parse_uri_query() to accept both "&" and ";" as argument separators
+ added support for the PUT and DELETE methods and for optional message bodies independent of the HTTP method
+ fixed handler matching to use a score for each handler and to check dynamic handlers also for a match if the fixed handlers don't provide a perfect match
+ fixed response handling to not overwrite the \c Connection header if present from the handler
+ fixed response handling to only return error reponses with codes >= 400
+ implemented theAbstractHttpSocketHandler handler class to support dedicated socket connections when switching protocols in handlers
+ do not add HTML to the msg body from explicit error responses from handlers
+ improved HTTP server log messages
+ added "family" argument to HttpServer::add*Listener*() methods
+ turned of TCP_NODELAY by default and use socket shutdown when closing sockets instead
+ set the listen backlog queue size to 100 by default (previously was hardcoded internally in Qore to 5)
+ use the new ThreadPool class introduced in Qore 0.8.8 to pre-allocate threads to reduce latency for new socket connections
+ improved handler matching algorithm
+ implemented many performance improvements
+ implemented support for simple string path matching when finding a handler for a request
+ added static AbstractHttpRequestHandler::redirect() to help in generating 301 Moved Permanently messages
* 2012-12-18 v0.3.6: David Nichols <david@qore.org>
+ fixed a race condition in tracking active requests in dynamic HTTP handlers and removing dynamic HTTP handlers
* 2012-09-20 v0.3.5: David Nichols <david@qore.org>
+ fixed bugs in regexes in the HttpServer::addListeners() and HttpServer::addListenersWithHandler() methods
+ updated module example code in summary
+ added "listener-id" to request context hash
* 2012-06-01 v0.3.4: David Nichols <david@qore.org>
+ added public parse_uri_query() function
* 2012-05-24 v0.3.3: David Nichols <david@qore.org>
+ updated to a user module
+ added support for custom redirects from user handlers
+ use the Mime module for mime definitions
* v0.3.2: David Nichols <david@qore.org>
+ added support for listeners with specific handler lists
+ added the ability to manage dynamic content handlers
+ implemented content-encoding handling flags in AbstractHttpRequestHandler
+ implemented support for "identity" encoding (if anyone ever sends it)
* v0.3.1: David Nichols <david@qore.org>
+ added ipv6 support in qore 0.8.2
* v0.3.0: David Nichols <david@qore.org>
+ added the ability to start and stop listeners on demand
* v0.2.9: David Nichols <david@qore.org>
+ updates for new SSL and timeout behavior with with Socket class with qore 0.8.1+
+ set socket encoding to UTF-8 by default
+ add "charset=utf-8" to Content-Type header if not already present
+ add "text/html" to Content-Type header if no content-type is given by the handler
+ fixed setting X.509 certificate and private key for HTTPS listeners
+ require qore >= 0.8.1 for new Socket features
* v0.2.8: David Nichols <david@qore.org>
+ converted to hard typing for use with %require-types
+ require qore >= 0.8.0 for new Socket features
* v0.2.7: David Nichols <david@qore.org>
+ set TCP_NODELAY on all sockets to ensure that clients get all data before closing the socket, especially in case of errors
+ require qore >= 0.7.4 for new Socket features
* v0.2.6: David Nichols <david@qore.org>
+ minor fixes for SOAP support
+ improved handler matching
* v0.2.5: David Nichols <david@qore.org>
+ minor fixes for SOAP support
* v0.2.4: David Nichols <david@qore.org>
+ improved Content-Type handling
+ improved URL/path support
* v0.2.3: David Nichols <david@qore.org>
+ bzip2 content-encoding support
* v0.2.2: David Nichols <david@qore.org>
+ basic authentication
* v0.2.1: David Nichols <david@qore.org>
+ implementing logic to handle "deflate" and "gzip" content-encoding
+ chunked content-encoding supported for POSTs
+ Date: header always sent as per HTTP 1.1 spec
* v0.2.0: David Nichols <david@qore.org>
+ modular/multiple listener support added
+ https support added
note that this server suffers from the following limitations, among many others:
+ not totally HTTP 1.1 compliant although claims to be
*/
namespace HttpServer {
hash parse_uri_query(string path);
string get_exception_string(hash ex);
};
// class containing handler info
class HttpServer::HandlerInfo {
public:
public :
string name;
AbstractHttpRequestHandler obj;
string path;
bool isregex;
// content type hash
hash ch;
*list shdr;
public:
constructor(string name, AbstractHttpRequestHandler obj, string path, bool isregex = True, *softlist content, *softlist shdr);
bool matchContentType(string ct);
int matchRequest(hash hdr, int score);
};
// class to implement handler-handling (private)
class HttpServer::HttpHandlerList {
public:
public :
hash handlers;
public:
private:
static checkSpecialHeaders(reference sh);
public:
setHandler(string name, string path, bool isregex = True, *softlist content, AbstractHttpRequestHandler obj, *softlist special_headers);
// matches a handler to the request
*HandlerInfo findHandler(hash hdr, reference score, bool final = False);
bool empty();
int size();
};
// class containing dynamic handler info
class HttpServer::DynamicHandlerInfo : public HttpServer::HandlerInfo {
public:
public :
Counter counter();
public:
constructor(string name, AbstractHttpRequestHandler obj, string path, bool isregex = True, *softlist content, *softlist shdr);
};
// maintains the request count for dynamic handlers (private)
class HttpServer::DynamicHandlerHelper {
public:
private:
public:
private :
Counter c;
public:
constructor(Counter c);
destructor();
};
// for dynamic handler-handling (private)
class HttpServer::DynamicHttpHandlerList : public HttpServer::HttpHandlerList {
public:
private :
RWLock dhl();
public:
setHandler(string name, string path, bool isregex, *softlist content_type, AbstractHttpRequestHandler obj, *softlist special_headers);
removeHandler(string name);
*DynamicHandlerInfo findHandler(hash hdr, reference score, reference dhh);
};
class HttpServer::AbstractAuthenticator {
public:
bool requiresAuthentication();
string getRealm();
authenticate(string user, string pass = "");
authenticateByIP(string ip, reference user);
private hash getAuthHeader();
private hash do401(string msg = "Authentication is required to access this server");
*hash authenticateRequest(HttpListener listener, hash hdr, reference cx);
};
class HttpServer::AbstractHttpRequestHandler {
public:
public :
*AbstractAuthenticator auth;
bool decompress = True;
bool decompress_to_string = True;
public:
constructor(*AbstractAuthenticator auth);
hash handleRequest(hash cx, hash hdr, *data body);
static *string getLogMessage(hash cx, hash api, reference params, *reference args);
*hash saveThreadLocalData();
restoreThreadLocalData(*hash data);
static hash makeResponse(int code, string fmt);
static hash makeResponse(hash hdr, int code, string fmt);
static hash makeResponse(int code, *data body, *hash hdr);
static hash make400(string fmt);
static hash make400(hash hdr, string fmt);
static hash make501(string fmt);
static hash make501(hash hdr, string fmt);
static hash redirect(hash cx, hash hdr, string path);
};
class HttpServer::AbstractUrlHandler : public HttpServer::AbstractHttpRequestHandler {
public:
public :
string url_root;
public:
constructor(string url_root, *AbstractAuthenticator auth);
string getRelativePath(string path);
};
class HttpServer::AbstractHttpSocketHandler : public HttpServer::AbstractHttpRequestHandler {
public:
private :
bool stop = False;
hash lh;
hash lsh;
Mutex m();
public:
constructor(*AbstractAuthenticator auth);
start(softstring lid, hash cx, hash hdr, Socket s);
stop(softstring lid);
stop();
abstract hash handleRequest(hash cx, hash hdr, *data b);
private abstract startImpl(softstring lid, hash cx, hash hdr, Socket s);
private stopImpl(string lid);
private stopImpl();
};
class HttpServer::HttpServer {
public:
public :
const Version = "0.3.7";
const ReadTimeout = 30000; // recvs timeout after 30 seconds
const PollTimeout = 5000; // check for exit every 5 seconds while waiting
// logging options
const LP_LOGPARAMS = 1 << 16;
const LP_LEVELMASK = LP_LOGPARAMS - 1;
const AIFlags = AI_PASSIVE | AI_ADDRCONFIG;
const HttpMethods = (
"HEAD": True,
"POST": True,
"PUT": True,
"DELETE": True,
"GET": True,
"OPTIONS": True,
//"TRACE": True,
//"CONNECT": True,
);
const HttpCodes = (
// 100s: Informational
"100": "Continue",
"101": "Switching Protocols",
// RFC 2518: WebDAV
"102": "Processing",
// 200s: Success
"200": "OK",
"201": "Created",
"202": "Accepted",
"203": "Non-Authoritative Information",
"204": "No Content",
"205": "Reset Content",
"206": "Partial Content",
// RFC 4918: WebDAV: The message body that follows is an XML message and can contain a number of separate response codes, depending on how many sub-requests were made
"207": "Multi-Status",
// RFC 5842: WebDAV: The members of a DAV binding have already been enumerated in a previous reply to this request, and are not being included again
"208": "Already Reported",
// RFC 3229
"226": "IM Used",
// 300s: Redirection
"300": "Multiple Choices",
"301": "Moved Permanently",
"302": "Found",
"303": "See Other",
"304": "Not Modified",
"305": "Use Proxy",
//"306": "(Reserved)",
"307": "Temporary Redirect",
// 400s: Client Errors
"400": "Bad Request",
"401": "Unauthorized",
"402": "Payment Required",
"403": "Forbidden",
"404": "Not Found",
"405": "Method Not Allowed",
"406": "Not Acceptable",
"407": "Proxy Authentication Required",
"408": "Request Timeout",
"409": "Conflict",
"410": "Gone",
"411": "Length Required",
"412": "Precondition Failed",
"413": "Request Entity Too Large",
"414": "Request-URI Too Long",
"415": "Unsupported Media Type",
"416": "Requested Range Not Satisfiable",
"417": "Expectation Failed",
// RFC 2324: http://tools.ietf.org/html/rfc2324
"418": "I'm a teapot",
// Returned by the Twitter Search and Trends API when the client is being rate limited
"420": "Enhance Yextern Calm",
// RFC 4918: WebDAV: The request was well-formed but was unable to be followed due to semantic errors
"422": "Unprocessable Entity",
// RFC 4918: WebDAV: The resource that is being accessed is locked
"423": "Locked",
// RFC 4918: WebDAV: The request failed due to failure of a previous request (e.g. a PROPPATCH)
"424": "Failed Dependency",
// Internet draft: Defined in drafts of "WebDAV Advanced Collections Protocol", but not present in "Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol"
"425": "Unordered Collection",
// RFC 2817: The client should switch to a different protocol such as TLS/1.0
"426": "Upgrade Required",
// RFC 6585: The origin server requires the request to be conditional. Intended to prevent "the 'lost update' problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict."
"428": "Precondition Required",
// RFC 6585: The user has sent too many requests in a given amount of time. Intended for use with rate limiting schemes
"429": "Too Many Requests",
// RFC 6585
"431": "Request Header Fields Too Large",
// 500s: Server Errors
"500": "Internal Server Error",
"501": "Not Implemented",
"502": "Bad Gateway",
"503": "Service Unavailable",
"504": "Gateway Timeout",
"505": "HTTP Version Not Supported",
"509": "Bandwidth Limit Exceeded",
// RFC 2774: Further extensions to the request are required for the server to fulfill it
"510": "Not Extended",
// RFC 6585: The client needs to authenticate to gain network access. Intended for use by intercepting proxies used to control access to the network (e.g. "captive portals" used to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot)
"511": "Network Authentication Required",
);
const ContentEncodings = (
"gzip": "gzip",
"deflate": "deflate",
"bzip2": "bzip2",
"x-gzip": "gzip",
"x-deflate": "deflate",
"x-bzip2": "bzip2",
);
const DefaultIdleThreads = 10;
public:
private :
*code logfunc;
*code errlogfunc;
// quit server flag
bool exit = False;
// if True then verbose exception info will be logged
bool debug;
Sequence seqSessions();
Sequence seqListeners();
string httpserverstring;
bool stopped = False;
// permanent handlers; these handlers are never removed
HttpHandlerList handlers();
// default handler
hash defaultHandler;
// hash of listeners keyed by listener ID
hash listeners;
// map of bind addresses to listener IDs
hash smap;
// map of listener names to listener IDs
hash nmap;
// listener Gate
Gate lm();
// running listener counter
Counter c();
// dynamic handlers
DynamicHttpHandlerList dhandlers();
// connection thread pool
ThreadPool threadPool(-1, DefaultIdleThreads);
// other misc response headers
hash hdr;
// override message body encoding if none is received from the sender; http://tools.ietf.org/html/rfc2616#section-3.7.1 states that it must be iso-8850-1
*string override_encoding;
public:
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));
destructor();
setDefaultTextEncoding(string enc);
string getDefaultTextEncoding();
final list addListenersWithHandler(string hname, AbstractHttpRequestHandler handler, hash lp, *code logger, *code errorlogger, *code stopc, *string name, int family = AF_UNSPEC);
hash addListener(softstring sock, *string cert_path, *string key_path, *string name, int family = AF_UNSPEC);
softlist addListeners(softstring sock, *string cert_path, *string key_path, *string name, int family = AF_UNSPEC);
list addINETListeners(*string node, softstring service, *string cert_path, *string key_path, *string name, int family = AF_UNSPEC);
copy();
hash getListeners();
hash getListenerInfo(softint id);
hash getListenerInfoName(string name);
int getListenerCount();
stopNoWait();
waitStop();
// only called from the listeners - do not call externally
listenerStopped(HttpListener l);
stop();
stopListener(softstring bind);
stopListenerID(softint id);
int getListenerTID(softint id);
setDefaultHandler(string name, AbstractHttpRequestHandler obj);
setHandler(string name, string path, *softlist content_type, AbstractHttpRequestHandler obj, *softlist special_headers, bool isregex = True);
setDynamicHandler(string name, string path, *softlist content_type, AbstractHttpRequestHandler obj, *softlist special_headers, bool isregex = True);
setHandler(string name, AbstractUrlHandler obj);
setDynamicHandler(string name, AbstractUrlHandler obj);
addHandlerToListener(softstring bind, string name, string path, *softlist content_type, AbstractHttpRequestHandler obj, *softlist special_headers, bool isregex = True);
addHandlerToListenerID(softint id, string name, string path, *softlist content_type, AbstractHttpRequestHandler obj, *softlist special_headers, bool isregex = True);
addHandlerToListener(softstring bind, string name, AbstractUrlHandler obj);
addHandlerToListenerID(softint id, string name, AbstractUrlHandler obj);
removeDynamicHandler(string name);
log();
logError();
logArgs(softlist args = ());
logErrorArgs(softlist args = ());
sendHttpError(HttpListener listener, hash cx, Socket s, int code, string msg, *hash extra_hdrs, *string encoding);
static string getURLFromBind(softstring bind, *string host);
setDebug(bool dbg = True);
bool getDebug();
startConnection(code c);
// don't reimplement this method; fix/enhance it in the module
final private HttpListener addListenerIntern(*string node, *softstring service, *Qore::SSLCertificate cert, *Qore::SSLPrivateKey key, *hash hi, *code logger, *code errorlogger, *code stopc, *string name, int family = AF_UNSPEC);
// don't reimplement this method; fix/enhance it in the module
static final private hash getSSLObjects(string cert_path, *string key_path);
// don't reimplement this method; fix/enhance it in the module
final private list addINETListenersIntern(*string node, softstring service, *hash sd, *hash lp, *code logger, *code errorlogger, *code stopc, *string name, int family = AF_UNSPEC);
// don't reimplement this method; fix/enhance it in the module
final private hash noHandlerError(hash cx, hash hdr, any body);
// handles an incoming request - do not call externally; this method is called by the listeners when a request is received
// don't reimplement this method; fix/enhance it in the module
final handleRequest(HttpListener listener, Socket s, reference cx, hash hdr, hash hh, *data body, bool head = False);
};
class HttpServer::HttpListener : public Qore::Socket {
public:
private :
HttpServer serv;
Sequence ss;
*SSLCertificate cert;
*SSLPrivateKey key;
bool ssl = False;
any socket;
hash socket_info;
// connection counter
Counter cThreads();
bool exit = False;
bool stopped = False;
int id;
// socket handler hash
hash shh;
// mutex
Mutex m();
// code references to external logging functions
*code logger;
*code errorlogger;
// stop notification closure
*code stopc;
string name;
const PollInterval = 1s;
const ListenQueue = 100;
public:
public :
// TID of the background listener thread
int tid;
// listener-specific handlers
HttpHandlerList handlers();
// default handler info
*HandlerInfo defaultHandler;
public:
// params: server, id, session ID sequence object, socket, rbac obj, [cert, key]
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);
addHandlers(hash hi);
setDefaultHandler(string name);
copy();
destructor();
string getName();
any getAddress();
int getID();
bool isSecure();
hash getInfo();
stopNoWait();
stop();
logResponse(hash cx, int code, *data body, *hash hdr);
logResponse(hash cx, hash rv);
log();
logError();
private mainThread();
// thread for handling communication per connection
private connectionThread(Socket s);
bool registerDedicatedSocket(softstring id, AbstractHttpSocketHandler h);
removeDedicatedSocket(softstring id, AbstractHttpSocketHandler h);
};
HttpServer::HttpServer::logError
logError()
called to log error information to the registered error log code
HttpServer::HttpServer::logErrorArgs
logErrorArgs(softlist args=())
calls the error log function/closure with the given args
HttpServer::HttpServer::logArgs
logArgs(softlist args=())
calls the log function/closure with the given args
AF_UNSPEC
const AF_UNSPEC
sprintf
string sprintf(string fmt,...)
HttpServer::HttpServer::getListeners
hash getListeners()
returns a hash of listener information
HttpServer::HttpServer::addListener
hash addListener(softstring sock, *string cert_path, *string key_path, *string name, int family=AF_UNSPEC)
adds a global listener to the server
HttpServer::get_exception_string
string get_exception_string(hash ex)
returns a multi-line string from the exception hash argument suitable for logging or output on the co...
HttpServer::AbstractHttpSocketHandler::handleRequest
abstract hash handleRequest(hash cx, hash hdr, *data b)
called by the HTTP server to handle incoming HTTP requests
HttpServer::HttpServer::setDebug
setDebug(bool dbg=True)
turns on or off debugging; when debugging is enabled more verbose error messages are reported ...
HttpServer::AbstractAuthenticator::getRealm
string getRealm()
returns the authentication realm as a string
HttpServer::AbstractHttpRequestHandler
abstract class that all HTTP request handler objects must inherit from
Definition: HttpServer.qm.dox.h:490
HttpServer::AbstractHttpRequestHandler::auth
*AbstractAuthenticator auth
the optional AbstractAuthenticator for requests to this handler
Definition: HttpServer.qm.dox.h:495
HttpServer::HttpServer::getURLFromBind
static string getURLFromBind(softstring bind, *string host)
returns a complete URL from a bind address
HttpServer::HttpServer::ReadTimeout
const ReadTimeout
default read timeout in ms
Definition: HttpServer.qm.dox.h:731
Qore::Socket
HttpServer::HttpServer::removeDynamicHandler
removeDynamicHandler(string name)
remove dynamic handler
HttpServer::AbstractHttpSocketHandler::lh
hash lh
hash of listener references; this is to stop all connections associated with a particular listener ...
Definition: HttpServer.qm.dox.h:618
HttpServer::AbstractHttpRequestHandler::constructor
constructor(*AbstractAuthenticator auth)
create the object optionally with the given AbstractAuthenticator
HttpServer::HttpServer::addHandlerToListenerID
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&#39;s id
HttpServer::HttpServer::destructor
destructor()
calls stop() and destroys the object
HttpServer::HttpServer::addHandlerToListener
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&#39;s name or bind address
True
const True
HttpServer::AbstractHttpSocketHandler::start
start(softstring lid, hash cx, hash hdr, Socket s)
called from the HTTP server after the handleRequest() method indicates that a dedicated connection sh...
HttpServer::AbstractUrlHandler::getRelativePath
string getRelativePath(string path)
returns the relative path anchored from the url_root if possible; URI query arguments are stripped of...
HttpServer::HttpServer::setDynamicHandler
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
HttpServer::HttpServer::DefaultIdleThreads
const DefaultIdleThreads
default number of idle threads to have waiting for new connections (accross all listeners) ...
Definition: HttpServer.qm.dox.h:868
HttpServer::HttpServer::stopListener
stopListener(softstring bind)
stops a single listener based on its name or bind address; does not return until all connections on t...
HttpServer::HttpServer::stopListenerID
stopListenerID(softint id)
stops a single listener based on its listener ID; does not return until all connections on the listen...
HttpServer::HttpServer::HttpMethods
const HttpMethods
supported HTTP methods
Definition: HttpServer.qm.dox.h:743
HttpServer::AbstractHttpRequestHandler::decompress
bool decompress
if POSTed data should be decompressed automatically if there is content-encoding
Definition: HttpServer.qm.dox.h:498
HttpServer::AbstractHttpSocketHandler::startImpl
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...
HttpServer::HttpServer::stop
stop()
stops all listeners; only returns when all connections are closed on all listeners ...
HttpServer::AbstractUrlHandler::constructor
constructor(string url_root, *AbstractAuthenticator auth)
creates the object based on the URL root and optional authenticator
HttpServer::AbstractHttpSocketHandler::m
Mutex m()
listener reference hash mutex
HttpServer::AbstractHttpSocketHandler::stopImpl
private stopImpl()
called from the HTTP server when the socket should be closed due to an external request; the start() ...
HttpServer::AbstractHttpRequestHandler::make501
static hash make501(string fmt)
creates a hash for an HTTP 501 error response with the response message body as a string ...
HttpServer::HttpServer::constructor
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
False
const False
HttpServer::AbstractAuthenticator::requiresAuthentication
bool requiresAuthentication()
called to check if the connection requires authentication
list
list list(...)
HttpServer::AbstractAuthenticator
abstract base class for external authentication
Definition: HttpServer.qm.dox.h:432
HttpServer::AbstractHttpRequestHandler::makeResponse
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...
HttpServer::AbstractHttpRequestHandler::make400
static hash make400(string fmt)
creates a hash for an HTTP 400 error response with the response message body as a string ...
HttpServer::HttpServer::getListenerInfo
hash getListenerInfo(softint id)
returns a hash of information about the listener given the listener ID
HttpServer::AbstractHttpRequestHandler::restoreThreadLocalData
restoreThreadLocalData(*hash data)
called after handleRequest() with any data returned from saveThreadData()
HttpServer::AbstractHttpSocketHandler::stop
stop()
called from the HTTP server when the socket should be closed due to an external request; the start() ...
HttpServer::HttpServer::PollTimeout
const PollTimeout
default poll timeout in ms
Definition: HttpServer.qm.dox.h:733
HttpServer::HttpServer::addListeners
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
HttpServer::AbstractHttpSocketHandler::constructor
constructor(*AbstractAuthenticator auth)
create the object optionally with the given AbstractAuthenticator
exit
nothing exit(softint rc=0)
Qore::SSLPrivateKey
HttpServer::parse_uri_query
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...
HttpServer::HttpServer::addListenersWithHandler
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 ...
HttpServer::AbstractHttpRequestHandler::getLogMessage
static *string getLogMessage(hash cx, hash api, reference params, *reference args)
helper method for handling log messages
HttpServer::HttpServer::sendHttpError
sendHttpError(HttpListener listener, hash cx, Socket s, int code, string msg, *hash extra_hdrs, *string encoding)
sends an HTTP error message on the socket
HttpServer::HttpServer::stopNoWait
stopNoWait()
stops all listeners; does not wait for all connections on the listeners to close
HttpServer::HttpServer::getDebug
bool getDebug()
returns the current status of the debug flag
HttpServer::AbstractHttpSocketHandler
abstract class that all HTTP dedicated socket handler objects must inherit from
Definition: HttpServer.qm.dox.h:610
HttpServer::AbstractUrlHandler
abstract class for HTTP request handlers anchored at a specific URL
Definition: HttpServer.qm.dox.h:586
HttpServer::HttpServer::waitStop
waitStop()
waits for all listeners to be stopped; call after calling HttpServer::stopNoWait() ...
HttpServer::AbstractHttpRequestHandler::handleRequest
hash handleRequest(hash cx, hash hdr, *data body)
will be called when a request is received that should be directed to the handler
Qore::SSLCertificate
HttpServer::HttpServer::AIFlags
const AIFlags
address info flags
Definition: HttpServer.qm.dox.h:740
HttpServer::AbstractHttpRequestHandler::decompress_to_string
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
HttpServer::HttpServer::copy
copy()
throws an exception; these objects do not support copying
HttpServer::HttpServer::Version
const Version
version of the HttpServer&#39;s implementation
Definition: HttpServer.qm.dox.h:729
HttpServer::HttpServer::setDefaultHandler
setDefaultHandler(string name, AbstractHttpRequestHandler obj)
sets the default request handler when no other handler can be matched
HttpServer::HttpServer
The HttpServer class implements a multithreaded HTTP server primarily designed for serving RPC-style ...
Definition: HttpServer.qm.dox.h:724
HttpServer::AbstractAuthenticator::authenticate
authenticate(string user, string pass="")
called to authenticate a user for a connection
HttpServer::HttpServer::setHandler
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
HttpServer::HttpServer::getListenerCount
int getListenerCount()
returns the number of running HTTP listeners
HttpServer::HttpListener
this class implements the listeners for the HttpServer class
Definition: HttpServer.qm.dox.h:1224
HttpServer::HttpServer::log
log()
called to log information to the registered log code
Qore::VersionString
const VersionString
HttpServer::AbstractHttpRequestHandler::saveThreadLocalData
*hash saveThreadLocalData()
called before handleRequest() any data returned here will be given to restoreThreadLocalData() after ...
HttpServer::HttpServer::addINETListeners
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
HttpServer::AbstractAuthenticator::authenticateByIP
authenticateByIP(string ip, reference user)
called when the connection requires authentication, but no authentication credentials were supplied...
hash
hash hash(object obj)
HttpServer::AbstractUrlHandler::url_root
string url_root
root part of URL for matching requests
Definition: HttpServer.qm.dox.h:591
AI_ADDRCONFIG
const AI_ADDRCONFIG
HttpServer::HttpServer::getListenerInfoName
hash getListenerInfoName(string name)
returns a hash of information about the listener given the listener name or bind ID ...
HttpServer::HttpServer::HttpCodes
const HttpCodes
map of HTTP result codes and text messages
Definition: HttpServer.qm.dox.h:755
AI_PASSIVE
const AI_PASSIVE
HttpServer::AbstractHttpRequestHandler::redirect
static hash redirect(hash cx, hash hdr, string path)
generates a redirect hash for the given path
HttpServer::AbstractAuthenticator::authenticateRequest
*hash authenticateRequest(HttpListener listener, hash hdr, reference cx)
primary method called to authenticate each request
HttpServer::AbstractHttpSocketHandler::lsh
hash lsh
hash of listener stop flags
Definition: HttpServer.qm.dox.h:621
HttpServer::HttpServer::ContentEncodings
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
HttpServer::HttpServer::getListenerTID
int getListenerTID(softint id)
gets the TID of a listener based on its listener ID