Contains information required to configure and perform a HTTP request.
Unique requests can be queued for async processing with CYIHTTPService. Request objects should be retained if cancellation is required.
#include <network/YiHTTPRequest.h>
Classes | |
struct | Metrics |
Public Types | |
enum | Method { Method::GET, Method::PUT, Method::POST, Method::DELETE, Method::PATCH, Method::HEAD } |
Supported HTTP request methods. More... | |
enum | CompressionType { CompressionType::Compressed, CompressionType::GZIP } |
Provides a hint to the server if compression can be used on the response data. More... | |
Public Member Functions | |
CYIHTTPRequest () | |
CYIHTTPRequest (const CYIUrl &url, Method method=Method::GET) | |
CYIHTTPRequest (const CYIServer &server) | |
CYIHTTPRequest (const CYIServer &server, const CYIUrl &url, Method method) | |
virtual | ~CYIHTTPRequest () |
void | SetMethod (Method method) |
void | SetServer (const CYIServer &server) |
void | SetPostData (const std::vector< char > &postData) |
void | SetPostData (CYIStringView postData) |
const std::vector< char > & | GetPostData () const |
bool | AddHeader (CYIString name, CYIString value) |
std::vector< CYIHTTPHeader > | GetHeaders () const |
uint64_t | GetUniqueID () const |
void | SetContextID (uint32_t contextID) |
uint32_t | GetContextID () const |
void | SetCompressionType (CompressionType compressionType) |
CYIHTTPRequest::CompressionType | GetCompressionType () const |
Method | GetMethod () const |
void | SetURL (const CYIUrl &url) |
const CYIUrl & | GetURL () const |
const CYIServer | GetServer () const |
void | SetNetworkTimeoutMs (uint32_t networkTimeoutMs) |
uint32_t | GetNetworkTimeoutMs () const |
void | SetConnectionTimeoutMs (uint32_t connectionTimeoutMs) |
uint32_t | GetConnectionTimeoutMs () const |
void | SetIsConnectivityProbe (bool isConnectivityProbe) |
bool | IsConnectivityProbe () const |
void | SetUserAgent (const CYIString &userAgent) |
void | SetUseCookies (bool useCookies) |
bool | IsUsingCookies () const |
const CYIHTTPHeader::CacheDirectives & | GetCacheControlDirectives () const |
CYIHTTPRequestPriv * | GetPriv () const |
void | SetMetricsEnqueueTime (std::chrono::duration< uint64_t, std::micro > time) |
void | SetMetricsRequestTime (std::chrono::duration< uint64_t, std::micro > time) |
CYIHTTPRequest::Metrics | GetMetrics () const |
Public Attributes | |
CYISignal< std::shared_ptr< CYIHTTPRequest >, std::shared_ptr< CYIHTTPResponse >, bool > | NotifyResponse |
Emitted when a response has been received for this request. The bool parameter will be true if the response is a cached response and false if the response is a server response. More... | |
CYISignal< std::shared_ptr< CYIHTTPRequest >, CYIHTTPService::HTTPStatusCode, CYIString > | NotifyError |
Emitted when an error occured processing this request, and no response is available. Parameters included are the status code (which may be from the server or locally generated if an error occured during processing) and an error string. More... | |
CYISignal< std::shared_ptr< CYIHTTPRequest >, std::shared_ptr< CYIHTTPResponse >, CYIHTTPService::HTTPStatusCode > | NotifyComplete |
Emitted when a success or failure response is received, or no response is available. Parameters included are request, response and status code. More... | |
|
strong |
Provides a hint to the server if compression can be used on the response data.
|
strong |
Supported HTTP request methods.
CYIHTTPRequest::CYIHTTPRequest | ( | ) |
Constucts a new CYIHTTPRequest::Method::GET request with no url configured.
CYIHTTPRequest::CYIHTTPRequest | ( | const CYIUrl & | url, |
Method | method = Method::GET |
||
) |
CYIHTTPRequest::CYIHTTPRequest | ( | const CYIServer & | server | ) |
Constucts a new CYIHTTPRequest::Method::GET request with no url configured.
|
virtual |
Adds a header to the request. Returns true if the header was added successfuly, false otherwise.
const CYIHTTPHeader::CacheDirectives& CYIHTTPRequest::GetCacheControlDirectives | ( | ) | const |
Returns the cache control directives present in the headers.
CYIHTTPRequest::CompressionType CYIHTTPRequest::GetCompressionType | ( | ) | const |
Returns the current compression type for the request.
uint32_t CYIHTTPRequest::GetConnectionTimeoutMs | ( | ) | const |
uint32_t CYIHTTPRequest::GetContextID | ( | ) | const |
Returns the request context ID.
std::vector<CYIHTTPHeader> CYIHTTPRequest::GetHeaders | ( | ) | const |
Returns the headers currently attached to the request.
Method CYIHTTPRequest::GetMethod | ( | ) | const |
Returns the current method.
CYIHTTPRequest::Metrics CYIHTTPRequest::GetMetrics | ( | ) | const |
Returns the timing metrics of the request.
uint32_t CYIHTTPRequest::GetNetworkTimeoutMs | ( | ) | const |
const std::vector<char>& CYIHTTPRequest::GetPostData | ( | ) | const |
Returns the POST data attached to this request.
CYIHTTPRequestPriv* CYIHTTPRequest::GetPriv | ( | ) | const |
Returns a raw pointer to the internal private implementation.
For internal use only.
const CYIServer CYIHTTPRequest::GetServer | ( | ) | const |
Returns the server for the request.
uint64_t CYIHTTPRequest::GetUniqueID | ( | ) | const |
Returns the unique request ID.
const CYIUrl& CYIHTTPRequest::GetURL | ( | ) | const |
Returns the full URL for the request.
bool CYIHTTPRequest::IsConnectivityProbe | ( | ) | const |
Query if the request will be used for connectivity probing.
For interal use by YiConnectivity.
bool CYIHTTPRequest::IsUsingCookies | ( | ) | const |
Returns whether the request will include cookies from the cookie store.
void CYIHTTPRequest::SetCompressionType | ( | CompressionType | compressionType | ) |
Sets the allowed compression type for the request.
void CYIHTTPRequest::SetConnectionTimeoutMs | ( | uint32_t | connectionTimeoutMs | ) |
Sets the maximum amount of time, in milliseconds, which the connection phase for a request may take. This is the time from when the request is dequeued and the transfer has started to when a response is received from the server.
void CYIHTTPRequest::SetContextID | ( | uint32_t | contextID | ) |
Sets a context ID, usable by client to identify an individual request.
void CYIHTTPRequest::SetIsConnectivityProbe | ( | bool | isConnectivityProbe | ) |
Called to tell the system that the request is for connectivity probing.
For internal use by YiConnectivity.
void CYIHTTPRequest::SetMethod | ( | Method | method | ) |
Sets the HTTP request method.
void CYIHTTPRequest::SetMetricsEnqueueTime | ( | std::chrono::duration< uint64_t, std::micro > | time | ) |
Sets the metrics time of when the corresponding network request was enqueued.
void CYIHTTPRequest::SetMetricsRequestTime | ( | std::chrono::duration< uint64_t, std::micro > | time | ) |
Sets the metrics time of when the corresponding network request was sent.
void CYIHTTPRequest::SetNetworkTimeoutMs | ( | uint32_t | networkTimeoutMs | ) |
Sets the maximum amount of time, in milliseconds, which a request may take. This is the time from when the request is dequeued and the transfer has started to when the transfer is complete.
void CYIHTTPRequest::SetPostData | ( | const std::vector< char > & | postData | ) |
Attach POST data to this request. This data is ignored for CYIHTTPRequest::Method::GET requests.
void CYIHTTPRequest::SetPostData | ( | CYIStringView | postData | ) |
Attach POST data to this request. The data is extracted from the string postData. This data is ignored for CYIHTTPRequest::Method::GET requests.
void CYIHTTPRequest::SetServer | ( | const CYIServer & | server | ) |
Sets the server for the request, to be used with OAuth requests.
void CYIHTTPRequest::SetURL | ( | const CYIUrl & | url | ) |
Set the URL for the request.
void CYIHTTPRequest::SetUseCookies | ( | bool | useCookies | ) |
Sets whether cookies from the cookies store are included in the request headers automatically. Cookies are not included by default.
void CYIHTTPRequest::SetUserAgent | ( | const CYIString & | userAgent | ) |
Set the user agent that will be used for this HTTP request. Setting the user agent to an empty string results in this HTTP request using the default user agent.
CYISignal<std::shared_ptr<CYIHTTPRequest>, std::shared_ptr<CYIHTTPResponse>, CYIHTTPService::HTTPStatusCode> CYIHTTPRequest::NotifyComplete |
Emitted when a success or failure response is received, or no response is available. Parameters included are request, response and status code.
CYISignal<std::shared_ptr<CYIHTTPRequest>, CYIHTTPService::HTTPStatusCode, CYIString> CYIHTTPRequest::NotifyError |
Emitted when an error occured processing this request, and no response is available. Parameters included are the status code (which may be from the server or locally generated if an error occured during processing) and an error string.
CYISignal<std::shared_ptr<CYIHTTPRequest>, std::shared_ptr<CYIHTTPResponse>, bool > CYIHTTPRequest::NotifyResponse |
Emitted when a response has been received for this request. The bool parameter will be true if the response is a cached response and false if the response is a server response.