76 namespace HttpServer {
93 "101":
"Switching Protocols",
102 "203":
"Non-Authoritative Information",
104 "205":
"Reset Content",
105 "206":
"Partial Content",
108 "207":
"Multi-Status",
111 "208":
"Already Reported",
117 "300":
"Multiple Choices",
118 "301":
"Moved Permanently",
121 "304":
"Not Modified",
124 "307":
"Temporary Redirect",
127 "400":
"Bad Request",
128 "401":
"Unauthorized",
129 "402":
"Payment Required",
132 "405":
"Method Not Allowed",
133 "406":
"Not Acceptable",
134 "407":
"Proxy Authentication Required",
135 "408":
"Request Timeout",
138 "411":
"Length Required",
139 "412":
"Precondition Failed",
140 "413":
"Request Entity Too Large",
141 "414":
"Request-URI Too Long",
142 "415":
"Unsupported Media Type",
143 "416":
"Requested Range Not Satisfiable",
144 "417":
"Expectation Failed",
147 "418":
"I'm a teapot",
150 "420":
"Enhance Yextern Calm",
153 "422":
"Unprocessable Entity",
159 "424":
"Failed Dependency",
162 "425":
"Unordered Collection",
165 "426":
"Upgrade Required",
168 "428":
"Precondition Required",
171 "429":
"Too Many Requests",
174 "431":
"Request Header Fields Too Large",
177 "500":
"Internal Server Error",
178 "501":
"Not Implemented",
179 "502":
"Bad Gateway",
180 "503":
"Service Unavailable",
181 "504":
"Gateway Timeout",
182 "505":
"HTTP Version Not Supported",
183 "509":
"Bandwidth Limit Exceeded",
186 "510":
"Not Extended",
189 "511":
"Network Authentication Required",
233 abstract log(
string fmt);
306 private hash getAuthHeader();
309 private hash do401(
string msg =
"Authentication is required to access this server");
425 private logChunk(
bool send,
int size);
698 stop(softstring lid);
string sprintf(string fmt,...)
logErrorArgs(*softlist args)
calls logError() with the given args
hash hdr
a hash of request headers
Definition: HttpServerUtil.qm.dox.h:367
private nothing recvImpl(hash v)
callback method for receiving chunked data; the default implementation in this base class does nothin...
const ReadTimeout
read timeout in ms
Definition: HttpServerUtil.qm.dox.h:87
const HttpCodes
map of HTTP result codes and text messages
Definition: HttpServerUtil.qm.dox.h:90
abstract class for streaming HTTP chunked requests/responses
Definition: HttpServerUtil.qm.dox.h:350
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:196
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:472
class providing automatic authentication for all requests
Definition: HttpServerUtil.qm.dox.h:327
*AbstractAuthenticator auth
the optional AbstractAuthenticator for requests to this handler
Definition: HttpServerUtil.qm.dox.h:477
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:658
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:254
*hash authenticateRequest(HttpListenerInterface listener, hash hdr, reference cx)
primary method called to authenticate each request
*data getMessageBody(Socket s, hash hdr, *data body, bool decode=True)
optionally retrieves and post-processes any message body
private hash sendResponse()
called to either create the response hash or send a chunked response directly
AbstractHttpRequestHandler handler
the request handler for the request
Definition: HttpServerUtil.qm.dox.h:361
bool decompress
if POSTed data should be decompressed automatically if there is content-encoding
Definition: HttpServerUtil.qm.dox.h:480
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...
constructor(HttpListenerInterface n_listener, AbstractHttpRequestHandler n_handler, Socket n_s, hash n_cx, hash n_hdr, any n_body)
creates the object with the given attributes
private hash getResponseHeaderMessageImpl()
this method should return the response message description hash
bool stream
if the handler supports streaming requests/responses with chunked data
Definition: HttpServerUtil.qm.dox.h:486
constructor(string n_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 ...
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:271
abstract any removeUserThreadContext(*string k)
removes the given key from the "uctx" context key; if no argument is provided, then the "uctx" contex...
static staticNotificationCleanup()
removes the thread-local data key in case the object is destroyed in another thread ...
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 ...
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 ...
timeout timeout_ms
send and receive timeout
Definition: HttpServerUtil.qm.dox.h:371
stop()
called from the HTTP server when the socket should be closed due to an external request; the start() ...
hash cx
the call context variable
Definition: HttpServerUtil.qm.dox.h:365
Socket s
the Socket object for the response
Definition: HttpServerUtil.qm.dox.h:363
private any sendImpl()
callback method for sending chunked data; the default implementation in this base class does nothing ...
const HttpServerVersion
version of the HttpServer's implementation
Definition: HttpServerUtil.qm.dox.h:78
static staticPersistenceCleanup()
removes the thread-local data key in case the object is destroyed in another thread ...
constructor(*AbstractAuthenticator auth)
create the object optionally with the given AbstractAuthenticator
*hash authenticateRequest(HttpListenerInterface listener, hash hdr, reference cx)
primary method called to authenticate each request
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...
HttpListenerInterface listener
an HttpListenerInterface object for the listener serving the request for logging purposes ...
Definition: HttpServerUtil.qm.dox.h:359
static binary encodeBody(string ce, data body)
encodes a message body with content-encoding
static *string getLogMessage(hash cx, hash api, reference params, *reference args)
helper method for handling log messages
this abstract class defines the interface for classes that provide logging methods ...
Definition: HttpServerUtil.qm.dox.h:227
abstract addUserThreadContext(hash uctx)
adds user-defined data to be returned in the "uctx" context key when serving requests from this liste...
const DefaultTimeout
default timeout in ms
Definition: HttpServerUtil.qm.dox.h:84
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: HttpServerUtil.qm.dox.h:650
abstract class for HTTP request handlers anchored at a specific URL
Definition: HttpServerUtil.qm.dox.h:626
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
const LP_LEVELMASK
mask for the log level
Definition: HttpServerUtil.qm.dox.h:199
private hash getResponseHeaderMessage()
this method returns the response message description hash by calling getResponseHeaderMessageImpl() ...
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:81
timeout timeout_ms
send and receive socket timeout in milliseconds
Definition: HttpServerUtil.qm.dox.h:489
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:483
hash handleRequest()
handles the request
authenticate(string user, string pass="")
called to authenticate a user for a connection
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:492
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 ...
private AbstractStreamRequest getStreamRequestImpl(HttpListenerInterface listener, Socket s, hash cx, hash hdr, *data body)
returns the AbstractStreamRequest object for handling chunked requests
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
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: HttpServerUtil.qm.dox.h:631
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
const PersistenceThreadKey
thread-local key string for the persistent flag
Definition: HttpServerUtil.qm.dox.h:495
hash lsh
hash of listener stop flags
Definition: HttpServerUtil.qm.dox.h:661
any body
any message body given in a non-chunked request; could already be deserialized
Definition: HttpServerUtil.qm.dox.h:369
bool isPersistent()
returns True if the current connection is persistent, False if not
private nothing checkPersistent(hash cx, hash hdr)
this method will throw an exception if a persistent connection cannot be granted