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>

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 } |
Static Public Member Functions | |
| static size_t | ReceiveResponse (char *pBuffer, size_t nSize, size_t nNumBytes, void *pContext) |
| static std::shared_ptr< CYIHTTPResponse > | CreateFromBytes (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) |
| CYIHTTPResponse::CYIHTTPResponse | ( | ) |
|
virtual |
|
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().
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.
| 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 |
| 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
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
| void CYIHTTPResponse::SetRequestID | ( | const int32_t | id | ) |
Set the requestId associated to that response.
|
protected |
|
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.