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>
Classes | |
struct | Metrics |
Public Types | |
enum | ContentType { ContentType::Text, ContentType::Image } |
enum | Status { Status::Connecting, Status::Downloading, Status::Completed, Status::Failed, Status::Cancelled } |
Static Public Member Functions | |
static size_t | ReceiveResponse (const char *pBuffer, size_t size, size_t numBytes, void *pContext) |
static size_t | ReceiveHeaders (const char *pBuffer, size_t size, size_t numBytes, void *pContext) |
Friends | |
template<typename T > | |
class | CYIHTTPResponseBuilder |
|
strong |
|
strong |
CYIHTTPResponse::CYIHTTPResponse | ( | ) |
|
virtual |
bool CYIHTTPResponse::AddHeader | ( | CYIStringView | name, |
CYIStringView | value | ||
) |
This adds a new http response header field key and header value value.
void CYIHTTPResponse::Finalize | ( | ) |
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.
int32_t CYIHTTPResponse::GetAgeValue | ( | ) | const |
Returns the 'Age' value in seconds provided by the server as part of the response header.
CYIString CYIHTTPResponse::GetBody | ( | ) | const |
Returns the HTTP response body portion only.
const CYIHTTPHeader::CacheDirectives& CYIHTTPResponse::GetCacheControlDirectives | ( | ) | const |
Returns the cache control type provided by the server.
const CYIString& CYIHTTPResponse::GetContentEncodingValue | ( | ) | const |
Returns the content encoding of the response.
size_t CYIHTTPResponse::GetContentLength | ( | ) | const |
Returns the content length of the response. This is the expected size in bytes of the response body.
const CYIString& CYIHTTPResponse::GetContentLocationValue | ( | ) | const |
Returns the string from the 'Content-location' header field.
ContentType CYIHTTPResponse::GetContentTypeValue | ( | ) | const |
Returns the content type of the reponse. The default value is ContentType::Text.
CYIDateTime CYIHTTPResponse::GetDateValue | ( | ) | const |
Returns the date value sent by the server for the 'Date' header field interpreted as per RFC 1123. Malformed values result in an invalid CYIDateTime object that can be queried with CYIDateTime::IsValid()
CYIString CYIHTTPResponse::GetDateValueRaw | ( | ) | 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.
const CYIString& CYIHTTPResponse::GetETagValue | ( | ) | const |
Returns the ETag value provided by the server.
CYIDateTime CYIHTTPResponse::GetExpiresValue | ( | ) | 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.
const CYIString& CYIHTTPResponse::GetHeader | ( | CYIStringView | name | ) | const |
Returns the header field with name. Returns Empty String if not found
const std::vector<CYIHTTPHeader>& CYIHTTPResponse::GetHeaders | ( | ) | const |
Returns the processed headers for the response. Follows RFC 2616 (4.2) Message Headers standard See https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
int32_t CYIHTTPResponse::GetHTTPStatusCode | ( | ) | const |
Returns the numerical HTTP status code from the response header.
const CYIString& CYIHTTPResponse::GetHTTPStatusReasonPhrase | ( | ) | const |
Returns a brief, purely informational, textual description of the status code to help a human understand the HTTP message.
CYIDateTime CYIHTTPResponse::GetLastModifiedDateValue | ( | ) | const |
Returns the date value by the server for the 'Last-Modified' header field interpreted as per RFC 1123. Malformed values result in an invalid CYIDateTime object that can be queried with CYIDateTime::IsValid()
CYIString CYIHTTPResponse::GetLastModifiedDateValueRaw | ( | ) | 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.
CYIHTTPResponse::Metrics CYIHTTPResponse::GetMetrics | ( | ) | const |
Returns the timing metrics of the response.
const std::vector<char>& CYIHTTPResponse::GetRawData | ( | ) | const |
Returns the body of the response as a byte array.
const CYIDateTime& CYIHTTPResponse::GetRequestTime | ( | ) | const |
Gets the time when the corresponding network request for this response was sent out. Request time is generally used for making age / freshness calculations for caching purposes.
const CYIDateTime& CYIHTTPResponse::GetResponseTime | ( | ) | const |
Gets the time when we started receiving this network response. Response time is generally used for making age / freshness calculations for caching purposes.
size_t CYIHTTPResponse::GetSize | ( | ) | const |
Returns the size of the HTTP response in bytes, including the body and header.
Status CYIHTTPResponse::GetTransferStatus | ( | ) | const |
Returns the transfer status of this response.
|
static |
Receives a single header line and processes that. Designed to work with libCurl's CURLOPT_HEADERFUNCTION callback where libcurl will pass each complete header line to this callback. A complete header line is terminated with a \r\n according to HTTP standard. The data passed in is not expected to be zero terminated.
|
static |
Receives a portion of the http response body and processes that. Designed to work with libCurl's CURLOPT_WRITEFUNCTION callback where libcurl will pass each chunk it receives. The data passed in is not expected to be zero terminated.
void CYIHTTPResponse::SetHTTPStatusCode | ( | int32_t | statusCode | ) |
Sets the HTTP Status Code received. If not set, GetHTTPStatusCode() will try to parse the header for the status code.
void CYIHTTPResponse::SetMetricsInitialResponseTime | ( | std::chrono::duration< uint64_t, std::micro > | time | ) |
Sets the metrics time of when the network response was first received.
void CYIHTTPResponse::SetMetricsTransferCompleteTime | ( | std::chrono::duration< uint64_t, std::micro > | time | ) |
Sets the metrics time of when the entire network response transfer was completed.
void CYIHTTPResponse::SetRequestID | ( | const int32_t | id | ) |
Sets the requestId associated with this response.
void CYIHTTPResponse::SetRequestTime | ( | const CYIDateTime & | time | ) |
Sets the time when the corresponding network request for this response was sent out. Request time is generally used for making age / freshness calculations for caching purposes.
void CYIHTTPResponse::SetTransferStatus | ( | Status | status | ) |
Sets the status of this response. This is typically done by the CYIHTTPService during processing.
|
friend |