Linderdaum Engine: happyhttp::HttpResponse Class Reference
Updated: Mon May 14 2012 05:02:41
happyhttp::HttpResponse Class Reference

HttpResponse class handles parsing of response data. More...

#include <HTTP.h>

List of all members.

Public Member Functions

const char * GetHeader (const char *name) const
 Retrieve a header or return 0 if not present.
bool Completed () const
 Check for operation completion.
int GetStatus () const
 Get the HTTP status code. Only valid once we've got the statusline.
const char * GetReason () const
 Get the HTTP response reason string. Only valid once we've got the statusline.
bool WillClose () const
 True if connection is expected to close after this response.

Public Attributes

std::string FLastError
 Last error code.

Protected Member Functions

 HttpResponse (const char *method, HttpConn &conn)
 Only HttpConn creates HttpResponses.
int Pump (const unsigned char *data, int datasize)
 Pump some data in for processing. Returns the number of bytes used or negative value on error. Will always return 0 when response is complete.
bool NotifyConnectionClosed ()
 Tell response that connection has closed.

Private Types

enum  {
  STATUSLINE, HEADERS, BODY, CHUNKLEN,
  CHUNKEND, TRAILERS, COMPLETE
}

Private Member Functions

void FlushHeader ()
 Process accumulated header data.
bool ProcessStatusLine (const std::string &line)
void ProcessHeaderLine (const std::string &line)
void ProcessChunkLenLine (const std::string &line)
int ProcessData (const unsigned char *data, int count)
 Handle some body data in (non)chunked mode. Returns number of bytes used.
void BeginBody ()
bool CheckClose ()
 Return true if we think server will automatically close connection.
void Finish ()
 Finish connection.

Private Attributes

enum happyhttp::HttpResponse:: { ... }  FState
HttpConnFConnection
 Link to owner.
std::string FMethod
 Request method name: "GET", "POST", etc.
std::string FVersionString
 HTTP-Version.
int FVersion
 10: HTTP/1.0 11: HTTP/1.x (where x>=1)
int FStatus
 Status-Code.
std::string FReason
 Reason-Phrase.
std::map< std::string,
std::string > 
FHeaders
 header/value pairs
int FBytesRead
 body bytes read so far
bool FChunked
 response is chunked?
int FChunkLeft
 bytes left in current chunk
int FLength
bool FWillClose
 connection will close at response end?
std::string FLineBuf
 Line accumulation for states that want it.
std::string FHeaderAccum
 Accumulation buffer for headers.

Friends

class HttpConn

Detailed Description

HttpResponse class handles parsing of response data.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
STATUSLINE 
HEADERS 
BODY 
CHUNKLEN 
CHUNKEND 
TRAILERS 
COMPLETE 

Constructor & Destructor Documentation

happyhttp::HttpResponse::HttpResponse ( const char *  method,
HttpConn conn 
) [protected]

Only HttpConn creates HttpResponses.


Member Function Documentation

void happyhttp::HttpResponse::BeginBody ( ) [private]

OK, we've now got all the headers read in, so we're ready to start on the body But we need to see what info we can glean from the headers first

Using chunked encoding ?

Mark unknown length

Is the length supplied ?

Store length

check for various cases where we expect zero-length body 1xx codes have no body

If we're not using chunked mode, and no length has been specified, assume connection will close at end.

now start reading body data!

bool happyhttp::HttpResponse::CheckClose ( ) [private]

Return true if we think server will automatically close connection.

HTTP1.1 - open unless "connection: close" is specified.

Older HTTP keep-alive header indicates persistant connection

bool happyhttp::HttpResponse::Completed ( ) const [inline]

Check for operation completion.

void happyhttp::HttpResponse::Finish ( ) [private]

Finish connection.

void happyhttp::HttpResponse::FlushHeader ( ) [private]

Process accumulated header data.

no flushing required

skip ':'

skip space

rest of line is value

const char * happyhttp::HttpResponse::GetHeader ( const char *  name) const

Retrieve a header or return 0 if not present.

const char* happyhttp::HttpResponse::GetReason ( ) const [inline]

Get the HTTP response reason string. Only valid once we've got the statusline.

int happyhttp::HttpResponse::GetStatus ( ) const [inline]

Get the HTTP status code. Only valid once we've got the statusline.

bool happyhttp::HttpResponse::NotifyConnectionClosed ( ) [inline, protected]

Tell response that connection has closed.

EOF can be valid

void happyhttp::HttpResponse::ProcessChunkLenLine ( const std::string &  line) [private]

chunklen in hex at beginning of line

got the whole body, check for trailing headers

int happyhttp::HttpResponse::ProcessData ( const unsigned char *  data,
int  count 
) [private]

Handle some body data in (non)chunked mode. Returns number of bytes used.

Chunk completed. Soak up the trailing CRLF before next chunk

Finish if we know we're done. Else we're waiting for connection close

void happyhttp::HttpResponse::ProcessHeaderLine ( const std::string &  line) [private]
bool happyhttp::HttpResponse::ProcessStatusLine ( const std::string &  line) [private]

Skip any leading space

Get version

Get status code

Rest of line is reason

TODO: support for HTTP/0.9

OK, now we expect headers!

int happyhttp::HttpResponse::Pump ( const unsigned char *  data,
int  datasize 
) [protected]

Pump some data in for processing. Returns the number of bytes used or negative value on error. Will always return 0 when response is complete.

Done line accumulation

bool happyhttp::HttpResponse::WillClose ( ) const [inline]

True if connection is expected to close after this response.


Friends And Related Function Documentation

friend class HttpConn [friend]

Member Data Documentation

body bytes read so far

response is chunked?

bytes left in current chunk

Accumulation buffer for headers.

std::map< std::string , std::string > happyhttp::HttpResponse::FHeaders [private]

header/value pairs

Last error code.

-1 if unknown

std::string happyhttp::HttpResponse::FLineBuf [private]

Line accumulation for states that want it.

std::string happyhttp::HttpResponse::FMethod [private]

Request method name: "GET", "POST", etc.

std::string happyhttp::HttpResponse::FReason [private]

Reason-Phrase.

enum { ... } happyhttp::HttpResponse::FState [private]

Status-Code.

10: HTTP/1.0 11: HTTP/1.x (where x>=1)

HTTP-Version.

connection will close at response end?


The documentation for this class was generated from the following files: