You.i Engine
CYIHTTPService Class Reference

#include <network/YiHTTPService.h>

Inheritance diagram for CYIHTTPService:

Public Types

enum  HTTPStatusCode {
  HTTPStatusCode::None = 0,
  HTTPStatusCode::OK = 200,
  HTTPStatusCode::NoContent = 204,
  HTTPStatusCode::RedirectFound = 302,
  HTTPStatusCode::NotModified = 304,
  HTTPStatusCode::Unauthorized = 401,
  HTTPStatusCode::NotFound = 404,
  HTTPStatusCode::InternalServerError = 500,
  HTTPStatusCode::YouiNetworkTimedOut = 997,
  HTTPStatusCode::YouiConnectionTimedOut = 998,
  HTTPStatusCode::Undefined = 999,
  HTTPStatusCode::YouiUndefined = Undefined
}
 

Public Member Functions

 ~CYIHTTPService ()
 
void SetMaxRedirects (uint32_t maxRedirects)
 
void SetNetworkTimeoutMs (uint32_t networkTimeoutMs)
 
void SetConnectionTimeoutMs (uint32_t connectionTimeoutMs)
 
void SetMaxConcurrentConnections (uint32_t maxConnections)
 
void SetNetworkConfiguration (const CYINetworkConfiguration &networkConfiguration)
 
void SetUserAgent (const CYIString &userAgent)
 
void SetProxyUrl (const CYIUrl &proxyUrl)
 
void Start ()
 
void Start (const CYINetworkConfiguration &networkConfiguration)
 
bool IsStarted () const
 
void Stop ()
 
bool EnqueueRequest (const std::shared_ptr< CYIHTTPRequest > &pRequest)
 
void CancelRequest (const std::shared_ptr< CYIHTTPRequest > &pRequest)
 
CYICacheContents GetCacheContents () const
 
void ClearCache ()
 
void ClearCookies ()
 
- Public Member Functions inherited from IYINetworkService
virtual ~IYINetworkService ()=default
 
- Public Member Functions inherited from CYISignalHandler
 CYISignalHandler ()
 
 CYISignalHandler (const CYISignalHandler &rSignalHandler)
 
virtual ~CYISignalHandler ()
 
CYISignalHandleroperator= (const CYISignalHandler &rSignalHandler)
 
void MoveToThread (CYIThread *pThread)
 This function allows the user to override the default thread affinity to any CYIThread that may or may not be running. More...
 
CYIThreadHandle GetThreadAffinity () const
 
void SetThreadAffinity (const CYIThreadHandle &rThreadAffinity)
 
virtual bool IsConnected () const
 
virtual bool IsConnected (const CYISignalBase &rSignal) const
 
void Disconnect (CYISignalBase &rSignal)
 
void DisconnectFromAllSignals ()
 
- Public Member Functions inherited from CYIThread::Listener
 Listener ()
 
virtual ~Listener ()
 
virtual void OnThreadStarted (CYIThread *)
 
virtual void OnThreadTerminated (CYIThread *)
 
virtual void OnThreadFinished (CYIThread *)
 

Static Public Member Functions

static CYIHTTPServiceGetInstance ()
 
static void SetSSLRootCertificate (const CYIString &rPath)
 

Public Attributes

CYISignal ServiceActive
 
CYISignal ServiceInactive
 

Friends

class CYIHTTPServicePriv
 

Member Enumeration Documentation

Enumerator
None 
OK 
NoContent 
RedirectFound 
NotModified 
Unauthorized 
NotFound 
InternalServerError 
YouiNetworkTimedOut 
YouiConnectionTimedOut 
Undefined 
YouiUndefined 

Constructor & Destructor Documentation

CYIHTTPService::~CYIHTTPService ( )

Member Function Documentation

void CYIHTTPService::CancelRequest ( const std::shared_ptr< CYIHTTPRequest > &  pRequest)
virtual

Cancels the previously enqueued HTTP request.

Implements IYINetworkService.

void CYIHTTPService::ClearCache ( )

Clears all cached responses.

void CYIHTTPService::ClearCookies ( )

Asynchronously clears all stored cookies.

Warning
There is no guarantee on when the cookies will actually clear because it needs to wait for all currently active requests to finish.
bool CYIHTTPService::EnqueueRequest ( const std::shared_ptr< CYIHTTPRequest > &  pRequest)
virtual

Queues an HTTP Request for async processing. Returns true if the request is accepted.

Connect to NotifyResponse and NotifyError on pRequest to be notified when the response is ready, or the request failed.

See also
CYIHTTPRequest

Implements IYINetworkService.

CYICacheContents CYIHTTPService::GetCacheContents ( ) const

Logs information about cached responses.

static CYIHTTPService* CYIHTTPService::GetInstance ( )
static
bool CYIHTTPService::IsStarted ( ) const

Returns whether the service has been started or not.

void CYIHTTPService::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.

Default is 30 seconds.

Note
All requests will use this timeout by default, to override on a per request basis use CYIHTTPRequest::SetConnectionTimeout().
void CYIHTTPService::SetMaxConcurrentConnections ( uint32_t  maxConnections)

Sets the maximum number of requests that can be active concurrently. Once the maximum is reached requests will remain in a queue until a request completes.

Note
Default maxinmum concurrent connection may vary per platform and setting this to std::numeric_limits<uint32_t>::max() will restore the default
void CYIHTTPService::SetMaxRedirects ( uint32_t  maxRedirects)

Sets the max number of redirects which the HTTP service will follow.

Default is 3.

void CYIHTTPService::SetNetworkConfiguration ( const CYINetworkConfiguration networkConfiguration)

Sets or modifies the network configuration settings. networkConfiguration allows you to to configure the underlying caches.

Modifying the network configuration after Start() has been called will only affect cache settings.

void CYIHTTPService::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.

Default is 60 seconds.

Note
All requests will use this timeout by default, to override on a per request basis use CYIHTTPRequest::SetNetworkTimeout().
void CYIHTTPService::SetProxyUrl ( const CYIUrl proxyUrl)

Set the proxy that will be used for future HTTP requests. Setting the proxy url to an empty url will reset the proxy to use the system settings.

Note
This API is intended for development/debugging purposes.
Warning
This API has no affect on Apple platforms (iOS, OSX, and tvOS). A proxy can still be used by changing the system proxy settings on those platforms.
static void CYIHTTPService::SetSSLRootCertificate ( const CYIString rPath)
static

Set the SSL root certificate for the network.

void CYIHTTPService::SetUserAgent ( const CYIString userAgent)

Set the user agent that will be used for future HTTP requests. Setting the user agent to an empty string results in future HTTP requests using the default user agent.

Note
The user agent of individual requests can also be set using CYIHTTPRequest::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
CYIHTTPRequest::SetUserAgent
void CYIHTTPService::Start ( )

Starts the service using the NetworkConfiguration provided by calling SetNetworkConfiguration().

Calling Start() before first calling SetNetworkConfiguration() will result in CYIHTTPService starting with default values for CYINetworkConfiguration::CYINetworkConfiguration. A default persistent cache will be created using the default data path if no cache path is provided.

The service does not accept requests until Start has been called.

Warning
A default persistent cache will not be created if this function is called before CYIApp::UserInit and no cache path is provided.
See also
CYINetworkConfiguration
void CYIHTTPService::Start ( const CYINetworkConfiguration networkConfiguration)

Start the service with the provided configuration settings. rNetworkConfiguration allows you to configure the underlying caches. A default persistent cache will be created using the default data path if no cache path is provided.

The service does not accept requests until Start has been called.

Warning
A default persistent cache will not be created if this function is called before CYIApp::UserInit and no cache path is provided.
See also
CYINetworkConfiguration
void CYIHTTPService::Stop ( )

Stop the service.

The service does not accept requests once Stop has been called.

Friends And Related Function Documentation

friend class CYIHTTPServicePriv
friend

Member Data Documentation

CYISignal CYIHTTPService::ServiceActive

Emitted when the service starts processing requests after a period of inactivity.

See also
ServiceInactive
CYISignal CYIHTTPService::ServiceInactive

Emitted when the service has finished processing all queued requests.

See also
ServiceActive

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