You.i Engine
CYIHTTPRequest Class Reference

Detailed Description

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.

See also
CYIHTTPService::EnqueueRequest
CYIHTTPService::CancelRequest

#include <network/YiHTTPRequest.h>

Inheritance diagram for CYIHTTPRequest:

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< CYIHTTPHeaderGetHeaders () 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 CYIUrlGetURL () 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::CacheDirectivesGetCacheControlDirectives () 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, CYIStringNotifyError
 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::HTTPStatusCodeNotifyComplete
 Emitted when a success or failure response is received, or no response is available. Parameters included are request, response and status code. More...
 

Member Enumeration Documentation

Provides a hint to the server if compression can be used on the response data.

See also
SetCompressionType
Enumerator
Compressed 

This is the default value, indicating that the server should not compress the response data.

GZIP 

Indicates that the server can compress the response data, but is not required to do so.

Supported HTTP request methods.

Enumerator
GET 

Retrieve the information identified by the request URL.

PUT 

Stores the post data as a resource identified by the request URL.

POST 

Submits the post data to be processed to a specified resource identified by the request URL.

DELETE 

Deletes the resource identified by the request URL.

PATCH 
HEAD 

Constructor & Destructor Documentation

CYIHTTPRequest::CYIHTTPRequest ( )

Constucts a new CYIHTTPRequest::Method::GET request with no url configured.

See also
SetURL
SetMethod
CYIHTTPRequest::CYIHTTPRequest ( const CYIUrl url,
Method  method = Method::GET 
)
See also
SetURL
SetMethod
CYIHTTPRequest::CYIHTTPRequest ( const CYIServer server)

Constucts a new CYIHTTPRequest::Method::GET request with no url configured.

See also
SetServer
CYIHTTPRequest::CYIHTTPRequest ( const CYIServer server,
const CYIUrl url,
Method  method 
)
virtual CYIHTTPRequest::~CYIHTTPRequest ( )
virtual

Member Function Documentation

bool CYIHTTPRequest::AddHeader ( CYIString  name,
CYIString  value 
)

Adds a header to the request. Returns true if the header was added successfuly, false otherwise.

Note
This API should not be used to set the user agent, using the header name 'User-Agent'. The header will not be added, and false will be returned in this case. Instead use CYIHTTPRequest::SetUserAgent.
See also
SetUserAgent
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.

Note
The default compression type is CYIHTTPRequest::CompressionType::Compressed.
uint32_t CYIHTTPRequest::GetConnectionTimeoutMs ( ) const
uint32_t CYIHTTPRequest::GetContextID ( ) const

Returns the request context ID.

See also
SetContextID(uint32_t)
std::vector<CYIHTTPHeader> CYIHTTPRequest::GetHeaders ( ) const

Returns the headers currently attached to the request.

Note
This API does not return information about the user agent.
See also
AddHeader
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.

See also
SetServer
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.

Note
This does not force compression but allows the server to compress the response data if it has the ability to do so.
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.

Note
If not set or set to 0 the CYIHTTPService connection timeout will be set on the request when the request is enqueued.
See also
CYIHTTPService::SetConnectionTimeoutMs
CYIHTTPService::EnqueueRequest
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.

See also
CYIHTTPRequest::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.

Note
If not set or set to 0 the CYIHTTPService network timeout will be set on the request when the request is enqueued.
See also
CYIHTTPService::SetNetworkTimeoutMs
CYIHTTPService::EnqueueRequest
void CYIHTTPRequest::SetPostData ( const std::vector< char > &  postData)

Attach POST data to this request. This data is ignored for CYIHTTPRequest::Method::GET requests.

Warning
If the data was already set, it will be overwritten by the new post data.
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.

Warning
If the data was already set, it will be overwritten by the new post data.
void CYIHTTPRequest::SetServer ( const CYIServer server)

Sets the server for the request, to be used with OAuth requests.

See also
CYIOAuthRequest
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.

Note
The HTTP Service must have cookie handling enabled via its network configuration for this to work.
See also
CYINetworkConfiguration::SetEnableCookieHandling
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.

Note
The user agent can also be set globally using CYIHTTPService::SetUserAgent. The user agent set using CYIHTTPRequest::SetUserAgent will override the user agent set using CYIHTTPService::SetUserAgent. A custom user agent will take precedence over the default user agent, if set in either class.
See also
CYIHTTPService::SetUserAgent

Member Data Documentation

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.

See also
CYIHTTPService::HTTPStatusCode.
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.


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