91 namespace HttpServer {
108 "101":
"Switching Protocols",
117 "203":
"Non-Authoritative Information",
119 "205":
"Reset Content",
120 "206":
"Partial Content",
123 "207":
"Multi-Status",
126 "208":
"Already Reported",
132 "300":
"Multiple Choices",
133 "301":
"Moved Permanently",
136 "304":
"Not Modified",
139 "307":
"Temporary Redirect",
142 "400":
"Bad Request",
143 "401":
"Unauthorized",
144 "402":
"Payment Required",
147 "405":
"Method Not Allowed",
148 "406":
"Not Acceptable",
149 "407":
"Proxy Authentication Required",
150 "408":
"Request Timeout",
153 "411":
"Length Required",
154 "412":
"Precondition Failed",
155 "413":
"Request Entity Too Large",
156 "414":
"Request-URI Too Long",
157 "415":
"Unsupported Media Type",
158 "416":
"Requested Range Not Satisfiable",
159 "417":
"Expectation Failed",
162 "418":
"I'm a teapot",
165 "420":
"Enhance Yextern Calm",
168 "422":
"Unprocessable Entity",
174 "424":
"Failed Dependency",
177 "425":
"Unordered Collection",
180 "426":
"Upgrade Required",
183 "428":
"Precondition Required",
186 "429":
"Too Many Requests",
189 "431":
"Request Header Fields Too Large",
192 "500":
"Internal Server Error",
193 "501":
"Not Implemented",
194 "502":
"Bad Gateway",
195 "503":
"Service Unavailable",
196 "504":
"Gateway Timeout",
197 "505":
"HTTP Version Not Supported",
198 "509":
"Bandwidth Limit Exceeded",
201 "510":
"Not Extended",
204 "511":
"Network Authentication Required",
315 abstract log(
string fmt);
390 hash getAuthHeader();
397 hash<HttpResponseInfo>
do401(
string msg =
"Authentication is required to access this server");
766 static hash<HttpResponseInfo>
makeResponse(
int code,
string fmt);
772 static hash<HttpResponseInfo>
makeResponse(
int code, *data body, *
hash hdr);
775 static hash<HttpResponseInfo>
make400(
string fmt);
778 static hash<HttpResponseInfo>
make400(
hash hdr,
string fmt);
781 static hash<HttpResponseInfo>
make501(
string fmt);
784 static hash<HttpResponseInfo>
make501(
hash hdr,
string fmt);
864 stop(softstring lid);
softbool close
set this key to True if the connection should be unconditionally closed when the handler returns ...
Definition: HttpServerUtil.qm.dox.h:226
static hash< HttpResponseInfo > redirect(hash cx, hash hdr, string path)
generates a redirect hash for the given path
static hash< HttpResponseInfo > make400(string fmt)
creates a hash for an HTTP 400 error response with the response message body as a string ...
bool reply_sent
this key can be set to True if the reply has already been sent (by a chunked callback for example) ...
Definition: HttpServerUtil.qm.dox.h:232
string sprintf(string fmt,...)
softbool close
set this key to True if the connection should be unconditionally closed when the handler returns ...
Definition: HttpServerUtil.qm.dox.h:250
logErrorArgs(*softlist args)
calls logError() with the given args
hash< HttpResponseInfo > do401(string msg="Authentication is required to access this server")
returns a 401 repsonse with the given string argument as the message body
authenticateByIP(string ip, reference< string > user)
called when the connection requires authentication, but no authentication credentials were supplied...
hash hdr
a hash of request headers
Definition: HttpServerUtil.qm.dox.h:474
const ReadTimeout
read timeout in ms
Definition: HttpServerUtil.qm.dox.h:102
const HttpCodes
map of HTTP result codes and text messages
Definition: HttpServerUtil.qm.dox.h:105
abstract class for streaming HTTP chunked requests/responses
Definition: HttpServerUtil.qm.dox.h:457
abstract hash handleRequest(hash cx, hash hdr, *data b)
called by the HTTP server to handle incoming HTTP requests
const LP_LOGPARAMS
bit for logging argument
Definition: HttpServerUtil.qm.dox.h:211
string getRealm()
returns the authentication realm as a string
abstract class that all HTTP request handler objects must inherit from
Definition: HttpServerUtil.qm.dox.h:613
class providing automatic authentication for all requests
Definition: HttpServerUtil.qm.dox.h:425
*AbstractAuthenticator auth
the optional AbstractAuthenticator for requests to this handler
Definition: HttpServerUtil.qm.dox.h:618
*hash< HttpResponseInfo > authenticateRequest(HttpListenerInterface listener, hash hdr, reference< hash > cx)
primary method called to authenticate each request
abstract log(string fmt)
called to log information to the registered log code
hash lh
hash of listener references; this is to stop all connections associated with a particular listener ...
Definition: HttpServerUtil.qm.dox.h:823
*hash hdr
set this key to a hash of extra header information to be returned with the response ...
Definition: HttpServerUtil.qm.dox.h:229
string maskData(string msg)
this method can be used to mask data in debug messages
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...
this abstract class defines the public interface of the private HttpListener class defined in the Htt...
Definition: HttpServerUtil.qm.dox.h:336
string http_mask_data(string msg)
this function can be used to mask data in log messages
AbstractStreamRequest getStreamRequestImpl(HttpListenerInterface listener, Socket s, hash cx, hash hdr, *data body)
returns the AbstractStreamRequest object for handling chunked requests
*data getMessageBody(Socket s, hash hdr, *data body, bool decode=True)
optionally retrieves and post-processes any message body
AbstractHttpRequestHandler handler
the request handler for the request
Definition: HttpServerUtil.qm.dox.h:468
string errlog
a string can be returned here which will be logged in the HTTP server's error log file (if any) ...
Definition: HttpServerUtil.qm.dox.h:238
bool decompress
if POSTed data should be decompressed automatically if there is content-encoding
Definition: HttpServerUtil.qm.dox.h:621
abstract startImpl(softstring lid, hash cx, hash hdr, Socket s)
called from the HTTP server after the handleRequest() method indicates that a dedicated connection sh...
bool stream
if the handler supports streaming requests/responses with chunked data
Definition: HttpServerUtil.qm.dox.h:627
constructor(string n_url_root, *AbstractAuthenticator auth)
creates the object based on the URL root and optional authenticator
string errlog
a string can be returned here which will be logged in the HTTP server's error log file (if any) ...
Definition: HttpServerUtil.qm.dox.h:262
Mutex m()
listener reference hash mutex
static hash< HttpResponseInfo > makeResponse(int code, string fmt)
creates a hash for an HTTP response with the response code and the response message body as a formatt...
bool requiresAuthentication()
called to check if the connection requires authentication
notifyClosed(*code c)
calls the argument when the persistent connection is closed
string http_get_url_from_bind(softstring bind, *string host)
returns a complete URL from a bind address
abstract base class for external authentication
Definition: HttpServerUtil.qm.dox.h:353
static staticNotificationCleanup()
removes the thread-local data key in case the object is destroyed in another thread ...
hash< HttpHandlerResponseInfo > sendResponse()
called to either create the response hash or send a chunked response directly
stopImpl()
called from the HTTP server when the socket should be closed due to an external request; the start() ...
restoreThreadLocalData(*hash data)
called after handleRequest() with any data returned from saveThreadData()
timeout timeout_ms
send and receive timeout
Definition: HttpServerUtil.qm.dox.h:478
stop()
called from the HTTP server when the socket should be closed due to an external request; the start() ...
*hash< HttpResponseInfo > authenticateRequest(HttpListenerInterface listener, hash hdr, reference< hash > cx)
primary method called to authenticate each request
nothing checkPersistent(hash cx, hash hdr)
this method will throw an exception if a persistent connection cannot be granted
hash cx
the call context variable
Definition: HttpServerUtil.qm.dox.h:472
Socket s
the Socket object for the response
Definition: HttpServerUtil.qm.dox.h:470
constructor(HttpListenerInterface n_listener, AbstractHttpRequestHandler n_handler, Socket n_s, hash n_cx, hash n_hdr, auto n_body)
creates the object with the given attributes
abstract auto removeUserThreadContext(*string k)
removes the given key from the "uctx" context key; if no argument is provided, then the "uctx" contex...
const HttpServerVersion
version of the HttpServer's implementation
Definition: HttpServerUtil.qm.dox.h:93
static staticPersistenceCleanup()
removes the thread-local data key in case the object is destroyed in another thread ...
*data body
the message body to return in the response; if this key is returned, then the reply is sent immediate...
Definition: HttpServerUtil.qm.dox.h:223
constructor(*AbstractAuthenticator auth)
create the object optionally with the given AbstractAuthenticator
nothing recv(hash v)
this is the primary callback for receiving chunked data; data will be logged, and then recvImpl() is ...
*hash hdr
set this key to a hash of extra header information to be returned with the response ...
Definition: HttpServerUtil.qm.dox.h:253
hash< HttpHandlerResponseInfo > getResponseHeaderMessage()
this method returns the response message description hash by calling getResponseHeaderMessageImpl() ...
HttpListenerInterface listener
an HttpListenerInterface object for the listener serving the request for logging purposes ...
Definition: HttpServerUtil.qm.dox.h:466
hash< HttpHandlerResponseInfo > handleRequest()
handles the request
static binary encodeBody(string ce, data body)
encodes a message body with content-encoding
nothing recvImpl(hash v)
callback method for receiving chunked data; the default implementation in this base class does nothin...
bool reply_sent
this key can be set to True if the reply has already been sent (by a chunked callback for example) ...
Definition: HttpServerUtil.qm.dox.h:256
this abstract class defines the interface for classes that provide logging methods ...
Definition: HttpServerUtil.qm.dox.h:309
abstract addUserThreadContext(hash uctx)
adds user-defined data to be returned in the "uctx" context key when serving requests from this liste...
auto body
any message body given in a non-chunked request; could already be deserialized
Definition: HttpServerUtil.qm.dox.h:476
int code
the HTTP return code (see HttpServer::HttpCodes for possible values)
Definition: HttpServerUtil.qm.dox.h:244
const DefaultTimeout
default timeout in ms
Definition: HttpServerUtil.qm.dox.h:99
string log
a string can be returned here which will be logged in the HTTP server's log file (if any) ...
Definition: HttpServerUtil.qm.dox.h:259
int code
the HTTP return code (see HttpServer::HttpCodes for possible values)
Definition: HttpServerUtil.qm.dox.h:220
abstract class that all HTTP dedicated socket handler objects must inherit from
Definition: HttpServerUtil.qm.dox.h:815
abstract class for HTTP request handlers anchored at a specific URL
Definition: HttpServerUtil.qm.dox.h:791
the return value of HTTP handler methods with potentially unserialized message bodies ...
Definition: HttpServerUtil.qm.dox.h:242
static data decodeBody(string ce, binary body, *string enc)
decodes a message body with content-encoding
hash< Util::UriQueryInfo > 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...
const LP_LEVELMASK
mask for the log level
Definition: HttpServerUtil.qm.dox.h:214
constructor(*AbstractAuthenticator n_auth, softbool n_stream=False)
create the object optionally with the given AbstractAuthenticator
const HttpServerString
default HTTP server string
Definition: HttpServerUtil.qm.dox.h:96
timeout timeout_ms
send and receive socket timeout in milliseconds
Definition: HttpServerUtil.qm.dox.h:630
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: HttpServerUtil.qm.dox.h:624
authenticate(string user, string pass="")
called to authenticate a user for a connection
logChunk(bool send, int size)
this method can be overridden in base classes to log each HTTP chunk sent
auto send()
this is the primary callback for sending chunked responses; first sendImpl() is called to get the raw...
setPersistent(bool p=True)
called externally to notify the handler that the connection will be persistent
const NotificationThreadKey
thread-local key string for notification callbacks
Definition: HttpServerUtil.qm.dox.h:633
the return value of HTTP handler methods where any message body has been serialized for sending over ...
Definition: HttpServerUtil.qm.dox.h:218
abstract logError(string fmt)
called to log error information to the registered error log code
*hash saveThreadLocalData()
called before handleRequest() any data returned here will be given to restoreThreadLocalData() after ...
logArgs(*softlist args)
calls log() with the given args
nothing http_set_reply_headers(Socket s, hash cx, reference rv, *string server_string)
helper function for setting HTTP response headers
string url_root
root part of URL for matching requests
Definition: HttpServerUtil.qm.dox.h:796
auto body
the message body to return in the response; for higher-level handlers this can be any data type that ...
Definition: HttpServerUtil.qm.dox.h:247
nothing persistentClosed()
called externally when a persistent connection is closed
static hash< HttpResponseInfo > make501(string fmt)
creates a hash for an HTTP 501 error response with the response message body as a string ...
const PersistenceThreadKey
thread-local key string for the persistent flag
Definition: HttpServerUtil.qm.dox.h:636
static *string getLogMessage(hash cx, hash api, reference params, *reference< string > args)
helper method for handling log messages
hash< HttpResponseInfo > getResponseHeaderMessageImpl()
this method should return the response message description hash
hash lsh
hash of listener stop flags
Definition: HttpServerUtil.qm.dox.h:826
hash< HttpResponseInfo > handleRequest(hash cx, hash hdr, *data body)
will be called when a request is received that should be directed to the handler
bool isPersistent()
returns True if the current connection is persistent, False if not
string log
a string can be returned here which will be logged in the HTTP server's log file (if any) ...
Definition: HttpServerUtil.qm.dox.h:235
auto sendImpl()
callback method for sending chunked data; the default implementation in this base class does nothing ...