![]() |
Qore HttpServerUtil Module Reference
0.9.4
|
abstract class that all HTTP dedicated socket handler objects must inherit from More...
Public Member Methods | |
constructor (*AbstractAuthenticator auth) | |
create the object optionally with the given AbstractAuthenticator More... | |
abstract hash | handleRequest (hash< auto > cx, hash< auto > hdr, *data b) |
called by the HTTP server to handle incoming HTTP requests More... | |
start (softstring lid, hash< auto > cx, hash< auto > hdr, Socket s) | |
called from the HTTP server after the handleRequest() method indicates that a dedicated connection should be established More... | |
stop (softstring lid) | |
called from the HTTP server when the socket should be closed due to an HTTP listener being stopped; the start() method for all connections on the particular listener should return as soon as possible after this method is called More... | |
stop () | |
called from the HTTP server when the socket should be closed due to an external request; the start() method should return as soon as possible after this method is called More... | |
![]() | |
constructor (*AbstractAuthenticator n_auth, softbool n_stream=False) | |
create the object optionally with the given AbstractAuthenticator More... | |
*data | getMessageBody (Socket s, hash< auto > hdr, *data body, bool decode=True) |
optionally retrieves and post-processes any message body | |
hash< HttpResponseInfo > | handleRequest (hash< auto > cx, hash< auto > hdr, *data body) |
will be called when a request is received that should be directed to the handler More... | |
hash< HttpResponseInfo > | handleRequest (HttpListenerInterface listener, Socket s, hash< auto > cx, hash< auto > hdr, *data body) |
top-level request handling method | |
bool | isPersistent () |
returns True if the current connection is persistent, False if not | |
string | maskData (string msg) |
this method can be used to mask data in debug messages More... | |
notifyClosed (*code c) | |
calls the argument when the persistent connection is closed | |
nothing | persistentClosed () |
called externally when a persistent connection is closed | |
restoreThreadLocalData (*hash< auto > data) | |
called after handleRequest() with any data returned from saveThreadData() More... | |
*hash< auto > | saveThreadLocalData () |
called before handleRequest() any data returned here will be given to restoreThreadLocalData() after the handleRequest() call More... | |
setPersistent (bool p=True) | |
called externally to notify the handler that the connection will be persistent | |
Private Member Methods | |
Mutex | m () |
listener reference hash mutex | |
abstract | startImpl (softstring lid, hash< auto > cx, hash< auto > hdr, Socket s) |
called from the HTTP server after the handleRequest() method indicates that a dedicated connection should be established More... | |
stopImpl (string lid) | |
called from the HTTP server when the socket should be closed because the listener is stopping; the start() method for all connections handled by the given listener should return as soon as possible after this method is called More... | |
stopImpl () | |
called from the HTTP server when the socket should be closed due to an external request; the start() method should return as soon as possible after this method is called | |
![]() | |
nothing | checkPersistent (hash< auto > cx, hash< auto > hdr) |
this method will throw an exception if a persistent connection cannot be granted | |
AbstractStreamRequest | getStreamRequestImpl (HttpListenerInterface listener, Socket s, hash< auto > cx, hash< auto > hdr, *data body) |
returns the AbstractStreamRequest object for handling chunked requests | |
Private Attributes | |
hash< string, int > | lh |
hash of listener references; this is to stop all connections associated with a particular listener | |
hash< string, bool > | lsh |
hash of listener stop flags | |
bool | stop = False |
stop listener flag | |
Additional Inherited Members | |
![]() | |
static data | decodeBody (string content_encoding, binary body, *string string_encoding) |
decodes a message body with content-encoding | |
static binary | encodeBody (string content_encoding, data body) |
encodes a message body with content-encoding | |
static *string | getLogMessage (hash< auto > cx, hash api, reference params, *reference< string > args) |
helper method for handling log messages More... | |
static hash< HttpResponseInfo > | make200 (string fmt) |
creates a hash for an HTTP 200 OK error response with the response message body as a string | |
static hash< HttpResponseInfo > | make200 (hash< auto > hdr, string fmt) |
creates a hash for an HTTP 200 OK error response with the response message body as a string | |
static hash< HttpResponseInfo > | make200 (hash< auto > hdr, InputStream chunked_body) |
creates a hash for an HTTP 200 OK error response with the response message body from an input stream | |
static hash< HttpResponseInfo > | make200 (InputStream chunked_body) |
creates a hash for an HTTP 200 OK error response with the response message body from an input stream | |
static hash< HttpResponseInfo > | make400 (string fmt) |
creates a hash for an HTTP 400 error response with the response message body as a string | |
static hash< HttpResponseInfo > | make400 (hash< auto > hdr, string fmt) |
creates a hash for an HTTP 400 error response with the response message body as a string | |
static hash< HttpResponseInfo > | make500 (string fmt) |
creates a hash for an HTTP 500 error response with the response message body as a string | |
static hash< HttpResponseInfo > | make500 (hash< auto > hdr, string fmt) |
creates a hash for an HTTP 500 error response with the response message body as a string | |
static hash< HttpResponseInfo > | make501 (string fmt) |
creates a hash for an HTTP 501 error response with the response message body as a string | |
static hash< HttpResponseInfo > | make501 (hash< auto > hdr, string fmt) |
creates a hash for an HTTP 501 error response with the response message body as a string | |
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 formatted string | |
static hash< HttpResponseInfo > | makeResponse (hash< auto > hdr, int code, string fmt) |
creates a hash for an HTTP response with the response code and the response message body as a formatted string | |
static hash< HttpResponseInfo > | makeResponse (int code, *data body, *hash< auto > hdr) |
creates a hash for an HTTP response with the response code and a literal response message body | |
static hash< HttpResponseInfo > | makeResponse (int code, *InputStream chunked_body, *hash< auto > hdr) |
creates a hash for an HTTP response with the response code and a response message body from an input stream More... | |
static hash< HttpResponseInfo > | redirect (hash< auto > cx, hash< auto > request_hdr, string path, int status_code=301, *hash< auto > response_hdr) |
generates a redirect hash for the given path | |
static | staticNotificationCleanup () |
removes the thread-local data key in case the object is destroyed in another thread | |
static | staticPersistenceCleanup () |
removes the thread-local data key in case the object is destroyed in another thread | |
![]() | |
*AbstractAuthenticator | auth |
the optional AbstractAuthenticator for requests to this handler | |
bool | decompress = True |
if POSTed data should be decompressed automatically if there is content-encoding | |
bool | decompress_to_string = True |
if automatically decompressed POSTed data should be converted to a string (if False, then it will be decompressed to a binary) | |
const | NotificationThreadKey = "_AHRH_pc" |
thread-local key string for notification callbacks | |
const | PersistenceThreadKey = "_AHRH_p" |
thread-local key string for the persistent flag | |
bool | stream |
if the handler supports streaming requests/responses with chunked data | |
timeout | timeout_ms = HttpServer::DefaultTimeout |
send and receive socket timeout in milliseconds | |
abstract class that all HTTP dedicated socket handler objects must inherit from
reimplement at least handleRequest() and startImpl() in subclasses
HttpServer::AbstractHttpSocketHandler::constructor | ( | *AbstractAuthenticator | auth | ) |
create the object optionally with the given AbstractAuthenticator
auth | the authentication object to use to authenticate connections (see AbstractAuthenticator); if no AbstractAuthenticator object is passed, then by default no authentication will be required |
|
pure virtual |
called by the HTTP server to handle incoming HTTP requests
To accept a new dedicated socket connection, make sure the return value returns code 101 (ie "Switching Protocols"
); after which this class's start() (and then startImpl()) methods are called
cx | call context hash; this hash will have the following keys:
|
hdr | incoming header hash; all keys will be converted to lower-case, additionally the following keys will be present:
|
b | message body, if any |
"code"
: assign to 101 (ie "Switching Protocols"
); if this is returned, then the start() method will be called with the Socket object for the new connection"hdr"
: (optional) set this key to a hash of extra header information to be returned with the response"code"
: the HTTP return code (see HttpServer::HttpCodes)"body"
: the message body to return in the response"close"
: (optional) set this key to True if the connection should be unconditionally closed when the handler returns"hdr"
: (optional) set this key to a hash of extra header information to be returned with the response HttpServer::AbstractHttpSocketHandler::start | ( | softstring | lid, |
hash< auto > | cx, | ||
hash< auto > | hdr, | ||
Socket | s | ||
) |
called from the HTTP server after the handleRequest() method indicates that a dedicated connection should be established
This method should not return until the connection is closed or the stop() method is called
lid | the listener ID |
cx | call context hash; this hash will have the following keys:
|
hdr | a hash of headers in the request |
s | the Socket object for the dedicated connection |
|
privatepure virtual |
called from the HTTP server after the handleRequest() method indicates that a dedicated connection should be established
This method should not return until the connection is closed or the stop() (and therefore stopImpl()) method is called
lid | the listener ID |
cx | call context hash; this hash will have the following keys:
|
hdr | a hash of headers in the request |
s | the Socket object for the dedicated connection |
HttpServer::AbstractHttpSocketHandler::stop | ( | softstring | lid | ) |
called from the HTTP server when the socket should be closed due to an HTTP listener being stopped; the start() method for all connections on the particular listener should return as soon as possible after this method is called
child classes should implement the stopImpl(string) method which is called from this method to implement custom stop actions for particular listeners
lid | the listener ID |
HttpServer::AbstractHttpSocketHandler::stop | ( | ) |
called from the HTTP server when the socket should be closed due to an external request; the start() method should return as soon as possible after this method is called
child classes should implement the stopImpl() method which is called from this method to implement custom stop actions
|
private |
called from the HTTP server when the socket should be closed because the listener is stopping; the start() method for all connections handled by the given listener should return as soon as possible after this method is called
lid | the listener ID |