FARGOS/VISTA Object Management Environment Core
..
|
Per-session HTTP state record. More...
#include <HTTPembeddedServer.hpp>
Classes | |
struct | ltCharPtrStr |
Public Types | |
typedef ssize_t(* | HTTPcallbackFP) (HTTP_SessionRecord *session, const char *cmd, char *url, unsigned char *block, size_t blockLen) |
Signature for HTTP callback routine. More... | |
typedef std::map< const char *, const char *, ltCharPtrStr > | OptionsAttrValMap_t |
![]() | |
enum | ParseState { READ_RESPONSE =1, READ_REQUEST, READ_HEADER_LINE, READ_CONTENT_BODY } |
Public Member Functions | |
HTTP_SessionRecord (IO_Processor *io, CircularBufferManager *mgr, const GenericSocketAddress *from, void *extraData=nullptr, size_t maxDocSize=1024 *128) | |
Create state record for current HTTP session. More... | |
~HTTP_SessionRecord () | |
void | addHTTPhandler (const char *cmd, HTTPcallbackFP routine) |
Add a handler routine for an HTTP request command. More... | |
void | setCloseAfterRequestFlag (bool doClose) |
Set close-when-request-complete flag. More... | |
virtual void | connectionEOF () |
User-exit called when EOF reached on client connection. More... | |
virtual int_fast32_t | processBlock (unsigned char *blockStart, size_t blockLen) VIRTUAL_OVERRIDE |
User-exit for receiving POSTed data. More... | |
virtual int | processHTTPheader (unsigned char *line, size_t lineLen) VIRTUAL_OVERRIDE |
User exit to process incoming HTTP header. More... | |
virtual bool | interestedInEvent (const class HTTPeventStateRecord *record) |
User-exit to filter out events when session has been converted into use with an HTTPstatusLog object. More... | |
![]() | |
Parse_And_Process_HTTP_Stream (size_t maxDocSize=1024 *128, ParseState initialState=READ_RESPONSE) | |
virtual | ~Parse_And_Process_HTTP_Stream () |
const char * | findHeaderAttribute (const char *headerElement) const |
virtual int | processHTTPresponse (unsigned char *line, size_t lineLen) |
User-exit for HTTP response line. More... | |
virtual int | processHTTPrequest (unsigned char *line, size_t lineLen) |
User-exit for HTTP request line. More... | |
int | processDocument (unsigned char *docStart, size_t docLen) VIRTUAL_OVERRIDE |
User-exit to process extracted document. More... | |
![]() | |
Extract_And_Process_Document_Stream (const char *docStart, const char *endTag, size_t maxDocSize=1024 *128) | |
virtual | ~Extract_And_Process_Document_Stream () |
int | scanAndProcessBuffer (const unsigned char *block, size_t blockLen) |
int | scanAndProcessBuffer (File_Buffer *bfrState) |
int | addIOblockThenProcess (SharedBufferAllocRecord *rec, IO_Processor *controller) |
Specialized interface to add incoming block from BufferRegion maintained by an IO_Processor. Block content is appended and then returned before any processing of the content is attempted. More... | |
Static Public Member Functions | |
static char * | convertHTTPescapes (char *bfr, int_fast32_t bfrLen=-1, bool nullTerminate=false) |
static int_fast32_t | parseOptions (OptionsAttrValMap_t *tbl, char *optionText, int_fast32_t optionLength=-1) |
Parse an HTTP request option string. Elements are separated by "&" characters; each subelement is expected to be a "var=value" pair. More... | |
static int | default_OPTIONS (HTTP_SessionRecord *session, const char *cmd, char *url, unsigned char *block, size_t blockLen) |
Default implementation to handle OPTIONS request. It emits Access-Control-Allow headers, assert GET, POST permitted. More... | |
Public Attributes | |
IO_Processor * | controller |
CircularBufferManager * | bfrMgr |
void * | userData |
GenericSocketAddress | fromAddress |
bool | closeWhenRequestComplete |
![]() | |
char | httpVersion [16] |
char | statusCode [8] |
char | responseReason [48] |
char | httpRequest [16] |
char | requestURL [1024] |
int32_t | contentLengthWanted |
std::map< std::string, std::string > | headerAttributes |
Protected Member Functions | |
virtual ssize_t | handleHTTPrequest (unsigned char *block, size_t blockLen) |
User-exit called when HTTP request read. Not normally overridden. More... | |
void | closeConnection () |
Close the connection associated with this HTTP session. More... | |
int_fast32_t | prepareResponseHeader (void *outputBfr, size_t bfrLen, uint_fast32_t statusCodeValue=200, const char *statusText="OK", const char *extraHeaders="", ssize_t contentLength=0, const char *extraContent="") |
ssize_t | sendResponse (const void *bfr, size_t bfrLen) |
![]() | |
int | scanForDocument () |
Protected Attributes | |
std::map< std::string, HTTPcallbackFP > | httpRequestHandlerTable |
![]() | |
ParseState | parseState |
ParseState | restartParseState |
![]() | |
enum Extract_And_Process_Document_Stream:: { ... } | scanState |
enum Extract_And_Process_Document_Stream:: { ... } | restartScanState |
unsigned char | documentStartPrefix [64] |
unsigned char | documentEndTag [64] |
File_Buffer * | pendingContent |
ssize_t | neededBlockLen |
size_t | documentStartLen |
size_t | documentEndLen |
Additional Inherited Members | |
![]() | |
enum | { FIND_NOTHING =0, FIND_DOC_START =1, FIND_END_TAG =2, FIND_BLOCK_LENGTH =3 } |
Per-session HTTP state record.
Custom applications are realized by implementing a subclass of HTTP_SessionRecord to handle the per-session behavior. The most trivial implementation will make an addHTTPhandler() call in the constructor and implement the corresponding method.
typedef ssize_t(* HTTP_SessionRecord::HTTPcallbackFP) (HTTP_SessionRecord *session, const char *cmd, char *url, unsigned char *block, size_t blockLen) |
Signature for HTTP callback routine.
typedef std::map<const char *, const char *, ltCharPtrStr> HTTP_SessionRecord::OptionsAttrValMap_t |
|
inline |
Create state record for current HTTP session.
io | points to the IO_Processor object controlling the stream processing. It should be deleted by some parent object. |
mgr | specifies the circular buffer manager used to buffer the input stream. Ownership is transferred to the HTTP_SessionRecord object. |
from | specifies the source of the incoming connection. |
extraData | allows application-specific data to be passed. |
maxDocSize | specifies the maximum size of an HTTP document to be pased to the Parse_And_Process_HTTP_Stream base class. |
References bfrMgr, closeWhenRequestComplete, controller, io(), and userData.
|
inline |
References bfrMgr.
|
inline |
Add a handler routine for an HTTP request command.
cmd | specifies the request to be handled, such as "GET" or "POST". |
routine | specifies the routine to be invoked. |
References httpRequestHandlerTable.
|
protected |
Close the connection associated with this HTTP session.
References _INVALID_DESCRIPTOR, controller, IO_Processor::descriptor, IO_Processor::desiredThreadState, LOG_CERR, LOG_ENDLINE, IO_Processor::READ_THREAD, SOCKET_CAST, and IO_Processor::stopThread().
Referenced by connectionEOF(), and handleHTTPrequest().
|
inlinevirtual |
User-exit called when EOF reached on client connection.
The default implementation calls closeConnection() to clean up.
References app(), closeConnection(), fromAddress, GenericSocketAddress::GenericSocketAddress_union::genericAddr, LOG_COMPONENT_CERR, LOG_ENDLINE, and GenericSocketAddress::socketAddress.
Referenced by HTTPembeddedServerBase::readHTTPstream().
|
static |
References fromHex.
Referenced by parseOptions().
|
static |
Default implementation to handle OPTIONS request. It emits Access-Control-Allow headers, assert GET, POST permitted.
References controller, IO_Processor::descriptor, and SOCKET_CAST.
|
protectedvirtual |
User-exit called when HTTP request read. Not normally overridden.
Default implementation will invoke the callback previously registered by addHTTPhandler() that corresponds to the incoming command.
References app(), AS_TEXT_BUFFER, closeConnection(), closeWhenRequestComplete, controller, IO_Processor::descriptor, Parse_And_Process_HTTP_Stream::findHeaderAttribute(), fromAddress, GenericSocketAddress::GenericSocketAddress_union::genericAddr, Parse_And_Process_HTTP_Stream::httpRequest, httpRequestHandlerTable, Parse_And_Process_HTTP_Stream::httpVersion, IFLOG_WHEN, LOG_COMPONENT_CERR, LOG_ENDLINE, Parse_And_Process_HTTP_Stream::requestURL, safe_strcpy, SOCKET_CAST, and GenericSocketAddress::socketAddress.
Referenced by processBlock(), and processHTTPheader().
|
inlinevirtual |
User-exit to filter out events when session has been converted into use with an HTTPstatusLog object.
Referenced by HTTPstatusLog::dumpEventsFromTime(), and HTTPstatusLog::publishEventState().
|
static |
Parse an HTTP request option string. Elements are separated by "&" characters; each subelement is expected to be a "var=value" pair.
tbl | is an attribute/value map into which the parsed attribute value pairs will be stored. Its key and value pointers will refer to addresses within optionText, so the storage associated with optionText must not be deleted while * the tbl map is accessed. |
optionText | is a string of HTML option text; if the length is specified, then the string content does not have to be terminated by a null character. |
optionLength | is an optional argument that specifies the length of optionText. If set to -1, the length will be determined at runtime using strlen(). |
NOTE: optionText will be modified.
References convertHTTPescapes().
|
protected |
|
inlinevirtual |
User-exit for receiving POSTed data.
blockStart | points to start of data |
blockLen | indicates length of provided data |
This overrides
Reimplemented from Parse_And_Process_HTTP_Stream.
References app(), AS_TEXT_BUFFER, fromAddress, GenericSocketAddress::GenericSocketAddress_union::genericAddr, handleHTTPrequest(), LOG_COMPONENT_CERR, LOG_ENDLINE, and GenericSocketAddress::socketAddress.
|
inlinevirtual |
User exit to process incoming HTTP header.
Extends the underlying Parse_And_Process_HTTP_Stream routine by invoking handleHTTPrequest() if the end of the headers is seen and no subsequent content is to be sent.
Reimplemented from Parse_And_Process_HTTP_Stream.
References app(), Parse_And_Process_HTTP_Stream::contentLengthWanted, fromAddress, GenericSocketAddress::GenericSocketAddress_union::genericAddr, handleHTTPrequest(), LOG_COMPONENT_CERR, LOG_ENDLINE, Parse_And_Process_HTTP_Stream::processHTTPheader(), and GenericSocketAddress::socketAddress.
|
protected |
References controller, IO_Processor::descriptor, and SOCKET_CAST.
|
inline |
Set close-when-request-complete flag.
doClose | specifies the desired state. |
By default, if a requesting client provides a "Connection: keep-alive" header, the connection will remain open after a request is processed. The connection can be forced to be closed by passing a value of true.
References closeWhenRequestComplete.
CircularBufferManager* HTTP_SessionRecord::bfrMgr |
Referenced by HTTP_SessionRecord(), and ~HTTP_SessionRecord().
bool HTTP_SessionRecord::closeWhenRequestComplete |
IO_Processor* HTTP_SessionRecord::controller |
Referenced by HTTPstatusLog::addHTTPsession(), HTTPstatusLog::becomeEventStream(), closeConnection(), default_OPTIONS(), HTTPstatusLog::dumpEventsFromTime(), HTTPstatusLog::dumpLinesFromTime(), handleHTTPrequest(), HTTP_SessionRecord(), HTTPstatusLog::publishEventState(), HTTPstatusLog::removeHTTPsession(), and sendResponse().
GenericSocketAddress HTTP_SessionRecord::fromAddress |
|
protected |
Referenced by addHTTPhandler(), and handleHTTPrequest().
void* HTTP_SessionRecord::userData |
Referenced by HTTP_SessionRecord().
![]() | Generated: Fri Jul 31 2020 18:19:16
Support Information |