Qore HttpServer Module Reference 0.3.8

- Main Page
- Related Pages
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Functions Variables Groups Pages
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
HttpServer::AbstractHttpRequestHandler Class Reference

abstract class that all HTTP request handler objects must inherit from More...

Inheritance diagram for HttpServer::AbstractHttpRequestHandler:
[legend]

## Public Member Functions
private nothing | checkPersistent (hash cx, hash hdr)
| this method will throw an exception if a persistent connection cannot be granted
| constructor (*AbstractAuthenticator auth, softbool stream=False)
| create the object optionally with the given AbstractAuthenticator More...
*data | getMessageBody (Socket s, hash hdr, *data body, bool decode=True)
| optionally retrieves and post-processes any message body
private AbstractStreamRequest | getStreamRequestImpl (HttpListener listener, Socket s, hash cx, hash hdr, *data body)
| returns the AbstractStreamRequest object for handling chunked requests
hash | handleRequest (hash cx, hash hdr, *data body)
| will be called when a request is received that should be directed to the handler More...
hash | handleRequest (HttpListener listener, Socket s, hash cx, hash hdr, *data body)
| top-level request handling method
nothing | persistentClosed ()
| called externally when a persistent connection is closed
| restoreThreadLocalData (*hash data)
| called after handleRequest() with any data returned from saveThreadData() More...
*hash | saveThreadLocalData ()
| called before handleRequest() any data returned here will be given to restoreThreadLocalData() after the handleRequest() call More...

## Static Public Member Functions
static data | decodeBody (string ce, binary body, *string enc)
| decodes a message body with content-encoding
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 More...
static hash | make400 (string fmt)
| creates a hash for an HTTP 400 error response with the response message body as a string
static hash | make400 (hash hdr, string fmt)
| creates a hash for an HTTP 400 error response with the response message body as a string
static hash | make501 (string fmt)
| creates a hash for an HTTP 501 error response with the response message body as a string
static hash | make501 (hash hdr, string fmt)
| creates a hash for an HTTP 501 error response with the response message body as a string
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 formatted string
static hash | makeResponse (hash 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 | makeResponse (int code, *data body, *hash hdr)
| creates a hash for an HTTP response with the response code and a literal response message body
static hash | redirect (hash cx, hash hdr, string path)
| generates a redirect hash for the given path

## Public Attributes
*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)
bool | persistent
| persistent connection flag
bool | stream
| if the handler supports streaming requests/responses with chunked data

## Detailed Description

abstract class that all HTTP request handler objects must inherit from

Reimplement handleRequest() in subclasses

For handlers supporting chunked data (both for receiving and sending), set stream to True in the constructor() method and implement getStreamRequestImpl() to return the HTTP stream request handler.

See Also
  AbstractStreamRequest for information about HTTP stream request handlers

## Member Function Documentation

HttpServer::AbstractHttpRequestHandler::constructor | ( | *AbstractAuthenticator | auth,
|  | softbool | stream = `False`
| ) |  |

create the object optionally with the given AbstractAuthenticator

Parameters

  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
  stream | if True then stream (i.e. HTTP chunked) requests and responses are handled and getStreamRequestImpl() will be used to return a valid AbstractStreamRequest object to handle requests

static *string HttpServer::AbstractHttpRequestHandler::getLogMessage | ( | hash | cx,
|  | hash | api,
|  | reference | params,
|  | *reference | args
| ) |  |
| static

helper method for handling log messages

Parameters

  cx | the call context hash
  api | the API description hash
  params | a reference to the call parameters; the call context hash will be added as the first argument
  args | an optional reference to a string describing the arguments

Returns
  a string if the message should be logged, otherwise NOTHING

hash HttpServer::AbstractHttpRequestHandler::handleRequest | ( | hash | cx,
|  | hash | hdr,
|  | *data | body
| ) |  |

will be called when a request is received that should be directed to the handler

Parameters

  cx | call context hash; this hash will have the following keys: `socket:` the bind address used to bind the listener (`"socket-info"` provides more detailed information) `socket-info`: a hash of socket information for the listening socket (as returned by Qore::Socket::getSocketInfo()) `peer-info`: a hash of socket information for the remote socket (as returned by Qore::Socket::getPeerInfo()) `url:` a hash of broken-down URL information (as returned from Qore::parse_url()) `id:` the unique HTTP connection ID `listener-id`: the HTTP server listener ID (see HttpServer::getListenerInfo()) `user:` the current RBAC username (if any)
  hdr | incoming header hash; all keys will be converted to lower-case, additionally the following keys will be present: `method:` the HTTP method received (ie `"GET"`, `"POST"`, etc) `path:` the HTTP path given in the request, after processing by Qore::decode_url() `http_version:` the HTTP version number in the request (either `"1.0"` or `"1.1"`)
  body | message body, if any

Returns
  a hash with the following keys:
  - `"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

Note
  the default implementation simply returns a 501 error code for all requests; reimplement this method in a subclass to provide the required functionality

HttpServer::AbstractHttpRequestHandler::restoreThreadLocalData | ( | *hash | data | ) |

called after handleRequest() with any data returned from saveThreadData()

Note
  the default implementation does nothing

*hash HttpServer::AbstractHttpRequestHandler::saveThreadLocalData | ( |  | ) |

called before handleRequest() any data returned here will be given to restoreThreadLocalData() after the handleRequest() call

Note
  the default implementation does nothing