All Classes Namespaces Functions Variables Groups Pages
HttpServer::AbstractHttpRequestHandler Class Reference

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

## Public Member Functions

| constructor (*AbstractAuthenticator auth)
| create the object optionally with the given AbstractAuthenticator
hash | handleRequest (hash cx, hash hdr, *data body)
| will be called when a request is received that should be directed to the handler
*hash | saveThreadLocalData ()
| called before handleRequest() any data returned here will be given to restoreThreadLocalData() after the handleRequest() call
| restoreThreadLocalData (*hash data)
| called after handleRequest() with any data returned from saveThreadData()

## Static Public Member Functions

static *string | getLogMessage (hash cx, hash api, reference params, *reference args)
| helper method for handling log messages

## 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)

## Detailed Description

abstract class that all HTTP request handler objects must inherit from

reimplement handleRequest) in subclasses

## Member Function Documentation

HttpServer::AbstractHttpRequestHandler::constructor | ( | *AbstractAuthenticator | auth | ) |

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

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 parseURL())
  - `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 decode_url() (Qore function)
  - `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