You.i Engine
CYIHTTPResponse Class Reference

Detailed Description

An HTTP response class which includes the header and body portions of the response.

Callers should be aware that the response will include the HTTP header by default. Use GetBody when only the body of the response is desired.

#include <network/YiHTTPResponse.h>

Inheritance diagram for CYIHTTPResponse:

Public Types

enum  CONTENT_TYPE {
  CONTENT_TYPE_TEXT,
  CONTENT_TYPE_IMAGE
}
 
enum  CACHE_CONTROL_TYPE {
  CACHE_CONTROL_TYPE_NONE,
  CACHE_CONTROL_TYPE_PRIVATE,
  CACHE_CONTROL_TYPE_PUBLIC,
  CACHE_CONTROL_TYPE_NOCACHE
}
 
enum  STATUS {
  DOWNLOADING,
  COMPLETED,
  FAILED,
  CANCELLED
}
 

Public Member Functions

 CYIHTTPResponse ()
 
virtual ~CYIHTTPResponse ()
 
void Reserve (uint32_t nSize) const
 
STATUS GetStatus () const
 
void SetStatus (STATUS eStatus)
 
const std::vector< char > & GetRawData () const
 
void SetRequestID (const int32_t id)
 
uint32_t GetSize () const
 
int32_t GetHeaderHTTPStatusCode () const
 
CYIString GetBody () const
 
const CYIStringGetHeader () const
 
const std::map< CYIString, CYIStringGetHeaders () const
 
bool IsCacheable () const
 
bool ShouldBeStored () const
 
int32_t GetMaxAgeInSeconds () const
 
int32_t GetExpiresInSeconds () const
 
const CYIStringGetETagValue () const
 
CACHE_CONTROL_TYPE GetCacheControlType () const
 
CONTENT_TYPE GetContentType () const
 
uint32_t GetContentLength () const
 
const CYIStringGetContentEncoding () const
 
const CYIStringGetLastModifiedDate () const
 
const CYIStringGetResponseDate () const
 
bool IsHeuristicallyExpired () const
 
bool IsExpired () const
 
void Process (const std::shared_ptr< CYIHTTPRequest > &pRequest)
 
- Public Member Functions inherited from CYIScriptableObject
 CYIScriptableObject ()
 
 CYIScriptableObject (const CYIScriptableObject &other)
 
CYIScriptableObjectoperator= (const CYIScriptableObject &other)
 
virtual ~CYIScriptableObject ()
 
CYIBindingImplementationGetBindingImplementation () const
 
void SetBindingImplementation (CYIBindingImplementation *pBindingImplementation)
 
virtual const CYIRuntimeTypeInfoGetRuntimeTypeInfoForScriptObject () const
 

Static Public Member Functions

static size_t ReceiveResponse (char *pBuffer, size_t nSize, size_t nNumBytes, void *pContext)
 
static std::shared_ptr< CYIHTTPResponseCreateFromBytes (char *pHeaders, size_t pHeadersSize, char *pResponse, size_t uResponseSize)
 

Protected Member Functions

void SetMaxAgeInSeconds (int32_t nMaxAge)
 
void SetExpiresInSeconds (int32_t nExpires)
 
void SetShouldStoreResponse (bool bStoreResponse)
 
void SetETagValue (const CYIString &rETag)
 
void SetContentType (CONTENT_TYPE eType)
 
void SetCacheControlType (CACHE_CONTROL_TYPE eType)
 
void SetContentEncoding (const CYIString &rContentEncoding)
 
void SetLastModifiedDate (const CYIString &rLastModifiedDate)
 
void SetResponseDate (const CYIString &rResponseDate)
 

Member Enumeration Documentation

Enumerator
CACHE_CONTROL_TYPE_NONE 
CACHE_CONTROL_TYPE_PRIVATE 
CACHE_CONTROL_TYPE_PUBLIC 
CACHE_CONTROL_TYPE_NOCACHE 
Enumerator
CONTENT_TYPE_TEXT 
CONTENT_TYPE_IMAGE 
Enumerator
DOWNLOADING 
COMPLETED 
FAILED 
CANCELLED 

Constructor & Destructor Documentation

CYIHTTPResponse::CYIHTTPResponse ( )
virtual CYIHTTPResponse::~CYIHTTPResponse ( )
virtual

Member Function Documentation

static std::shared_ptr<CYIHTTPResponse> CYIHTTPResponse::CreateFromBytes ( char *  pHeaders,
size_t  pHeadersSize,
char *  pResponse,
size_t  uResponseSize 
)
static
CYIString CYIHTTPResponse::GetBody ( ) const

Returns the HTTP response body portion only.

CACHE_CONTROL_TYPE CYIHTTPResponse::GetCacheControlType ( ) const

Returns the cache control type provided by the server.

const CYIString& CYIHTTPResponse::GetContentEncoding ( ) const

Returns the content encoding of the response.

uint32_t CYIHTTPResponse::GetContentLength ( ) const

Returns the content length of the response. This is the expected size in bytes of the response body.

CONTENT_TYPE CYIHTTPResponse::GetContentType ( ) const

Returns the content type of the reponse. The default value is CONTENT_TYPE_TEXT.

const CYIString& CYIHTTPResponse::GetETagValue ( ) const

Returns the ETag value provided by the server.

int32_t CYIHTTPResponse::GetExpiresInSeconds ( ) const

Returns the amount of time in seconds at which the HTTP response should expire. This comes from the 'Expires" header field.

const CYIString& CYIHTTPResponse::GetHeader ( ) const

Returns the HTTP response header portion only.

int32_t CYIHTTPResponse::GetHeaderHTTPStatusCode ( ) const

Returns the numerical HTTP status code from the header of the response. To get the transfer status of the response see GetStatus().

const std::map<CYIString, CYIString> CYIHTTPResponse::GetHeaders ( ) const

Returns the HTTP response headers in key/value form. Follows RFC 2616 (4.2) Message Headers standard See https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2

const CYIString& CYIHTTPResponse::GetLastModifiedDate ( ) const

Returns the exact date string sent by the server for the 'Last-Modified' header field. This should represent the last time the requested data was modified expressed in the server's time. The format should be RFC 1123.

int32_t CYIHTTPResponse::GetMaxAgeInSeconds ( ) const

Returns the maximum age in seconds for which the HTTP reponse can be cached. This comes from the 'max-age' part of the 'Cache-Control' header field.

const std::vector<char>& CYIHTTPResponse::GetRawData ( ) const

Returns the body of the response response as a byte array.

const CYIString& CYIHTTPResponse::GetResponseDate ( ) const

Returns the exact date string sent by the server for the 'Date' header field. This should represent the date that the response message was created by the server expressed in the server's time. The format should be RFC 1123.

uint32_t CYIHTTPResponse::GetSize ( ) const

Returns the size of the HTTP response in bytes, includes the body and header.

STATUS CYIHTTPResponse::GetStatus ( ) const

Returns the transfer status of this response. To get the HTTP status code for this response see GetHeaderHTTPStatusCode().

bool CYIHTTPResponse::IsCacheable ( ) const

Returns true if the HTTP response is cacheable, according to what settings are sent by the server. This will return true if the response can be cached using heuristic expiration.

bool CYIHTTPResponse::IsExpired ( ) const

Returns true if this response is older than its max age. Does not factor in heuristic expiry.

A response is expired if it has a max age in seconds and that much time has passed since the Date field specified in the response header.

See also
IsHeuristicallyExpired
GetResponseDate
GetMaxAgeInSeconds
bool CYIHTTPResponse::IsHeuristicallyExpired ( ) const

Uses heuristics to check if this response is stale.

If the age of the response is longer than 10% of the age of the asset on the server, it should be expired. Note that we only use values returned by the server for this check. Therefore if either the 'Last-Modified' or 'Date' header fields are missing, the heuristic check can't be run. True will be returned in this case.

timeItemHasBeenCached < (timeSinceLastModifiedOnServer * 0.1)

void CYIHTTPResponse::Process ( const std::shared_ptr< CYIHTTPRequest > &  pRequest)

This method will parse the response looking for specific values related to content type, caching parameters, and preparing the class for general use. It should only be called once all of the data for the response had been received.

static size_t CYIHTTPResponse::ReceiveResponse ( char *  pBuffer,
size_t  nSize,
size_t  nNumBytes,
void *  pContext 
)
static
void CYIHTTPResponse::Reserve ( uint32_t  nSize) const

If you know ahead of time the size of the response data, call this to reserve the space and avoid tons of allocation

void CYIHTTPResponse::SetCacheControlType ( CACHE_CONTROL_TYPE  eType)
protected
void CYIHTTPResponse::SetContentEncoding ( const CYIString rContentEncoding)
protected
void CYIHTTPResponse::SetContentType ( CONTENT_TYPE  eType)
protected
void CYIHTTPResponse::SetETagValue ( const CYIString rETag)
protected
void CYIHTTPResponse::SetExpiresInSeconds ( int32_t  nExpires)
protected
void CYIHTTPResponse::SetLastModifiedDate ( const CYIString rLastModifiedDate)
protected
void CYIHTTPResponse::SetMaxAgeInSeconds ( int32_t  nMaxAge)
protected
void CYIHTTPResponse::SetRequestID ( const int32_t  id)

Set the requestId associated to that response.

void CYIHTTPResponse::SetResponseDate ( const CYIString rResponseDate)
protected
void CYIHTTPResponse::SetShouldStoreResponse ( bool  bStoreResponse)
protected
void CYIHTTPResponse::SetStatus ( STATUS  eStatus)

Set the status of this response. This is typically done by the CYIHTTPService during processing.

bool CYIHTTPResponse::ShouldBeStored ( ) const

Returns true if the HTTP response should be written to a storage medium, according to information sent by the server.


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