Public Member Functions | Static Public Member Functions | List of all members
Celartem::HttpManager Class Referenceabstract

#include <cel_http.h>

Inheritance diagram for Celartem::HttpManager:
Inheritance graph
[legend]

Public Member Functions

virtual AutoPtr< HttpConnectioncreateConnection (const String &inHostName, u16 inPort=80)=0
 
virtual AutoPtr< HttpConnectioncreateSecureConnection (const String &inHostName, u16 inPort=443, bool inVerifyServer=false)=0
 
virtual AutoPtr< HttpStoragecreateHttpStorage (const String &inUrl, bool inVerifyServer=false, DuplicateStreamCallback inLoadCallback=NULL, void *inContext=NULL)
 
virtual void setProxy (ProxyType inType, const String &inHostName="", u16 inPort=0)=0
 
virtual CredentialProvidergetCredentialProvider ()=0
 
void downloadFile (const String &inSaveFileName, const String &inUrl, bool inVerifyServer=false, DuplicateStreamCallback inLoadCallback=NULL, void *inContext=NULL)
 
- Public Member Functions inherited from Celartem::Referable
 Referable ()
 
void addRef () const
 
void releaseRef () const
 
size_t getReferenceCount () const
 

Static Public Member Functions

static AutoPtr< HttpManagercreate (const String &inUserAgentName=NullString, CredentialProvider *inCredentialProvider=NULL)
 
static String getDefaultUserAgentName ()
 
static String getUserAgentPlatformSpec ()
 
- Static Public Member Functions inherited from Celartem::Referable
static void dumpDbgAllRefCount ()
 

Detailed Description

This class manages the HTTP configurations and create connections. The following sample tries to fetch the index page of http://www.celartem.com .

void fetchPage(SimpleArray<u8>& buffer)
{
// This client does not support any authentication mechanism.
Autoptr<HttpManager> httpMan
= HttpManager::create("Simple HTTP Test/1.0");
// If you have only URL, not hostname, use
// Url::separateUrl function.
AutoPtr<HttpConnection> conn
= httpMan->createConnection("www.celartem.com");
// fetch "/"
AutoPtr<HttpRequestStream> req
= conn->createRequestStream("GET", "/");
// get the response
AutoPtr<HttpResponseStream> res = req->post();
// check status
unsigned int ret = res->getStatusCode();
if(ret / 100 != 2)
celThrow(errOperationFailed); // non 2XX response
// load the content
size_t size = res->getContentSize();
buffer.allocate(size);
res->readBytes(&buffer[0], size);
}

Please note that this sample is just to indicate how to use createConnection, HttpRequestStream and HttpResponseStream, there are another way to do it easier; for more information, see createHttpStorage .

See Also
HttpConnection, HttpRequestStream, HttpResponseStream

Member Function Documentation

static AutoPtr<HttpManager> Celartem::HttpManager::create ( const String inUserAgentName = NullString,
CredentialProvider inCredentialProvider = NULL 
)
static

This method creates an HttpManager instance that uses the specified configuration. It also initializes the network environment if needed. You should synchronize creation of the requests; only 1 request can exist at a time on a connection.
This method is thread-safe; all the calls to this method is automatically serialized.

Parameters
inUserAgentNameUser Agent Name for your application. If this value is not specified (or NullString), it uses system default.
inCredentialProviderPointer to a class instance to get credential information.
Returns
Pointer to the newly created HttpManager instance.
virtual AutoPtr<HttpConnection> Celartem::HttpManager::createConnection ( const String inHostName,
u16  inPort = 80 
)
pure virtual

This method does create a connection object between this machine and the specified host. This method is thread-safe; all the calls to this method is automatically serialized.

Parameters
inHostNameIt specifies the remote host to connect, it could be string notation of hostname or dotted-decimal style IP address such as "192.168.10.23". If you only want to fetch a resource (file) from Web, you had better use createHttpStorage instead of this method.
inPortIt specifies the port to connect. HTTP (non-secure connection) uses 80 by default. 0 to use the default (80).
Returns
Pointer to the newly created HttpConnection instance.
virtual AutoPtr<HttpStorage> Celartem::HttpManager::createHttpStorage ( const String inUrl,
bool  inVerifyServer = false,
DuplicateStreamCallback  inLoadCallback = NULL,
void *  inContext = NULL 
)
virtual

This method create read-only storage based on HTTP connection. Whether using HTTP or HTTPS is automatically determined by examining scheme specification in the URL.
The storage created by this method internally uses HttpConnection. This method is thread-safe; all the calls to this method is automatically serialized.

Parameters
inUrlURL of the resource to access. It should be escaped before passing to this method.
inVerifyServerWhether the server connected to should be verified or not.
inLoadCallbackCallback function called during fetching the data from the HTTP connection.
inContextContext used on the callback.
Returns
Pointer to the newly created Storage instance.
See Also
Url, createConnection, createSecureConnection

The following is a sample use of this method:

void fetchPage(SimpleArray<u8>& buffer)
{
// This client does not support any authentication mechanism.
AutoPtr<HttpManager> httpMan
= HttpManager::create("Simple HTTP Test/1.0");
AutoPtr<HttpStorage> storage
= httpMan->createHttpStorage("http://www.example.com/test/picture.tif");
// load the content
size_t size = storage->getSize();
buffer.allocate(size + 1);
storage->readBytes(&buffer[0], size);
buffer[size] = 0;
}

Although almost same function can be realized by createConnection method, this one is more straightforward and easy than it.

virtual AutoPtr<HttpConnection> Celartem::HttpManager::createSecureConnection ( const String inHostName,
u16  inPort = 443,
bool  inVerifyServer = false 
)
pure virtual

This method does create a secure connection object between this machine and the specified host. This method is thread-safe; all the calls to this method is automatically serialized.

Parameters
inHostNameIt specifies the remote host to connect, it could be string notation of hostname or dotted-decimal style IP address such as "192.168.10.23".
If you only want to fetch a resource (file) from Web, you had better use createHttpStorage instead of this method.
inPortIt specifies the port to connect. HTTPS (Secure HTTP connection) uses 443 by default. 0 to use the default (443).
inVerifyServerWhether the server connected to should be verified or not.
inLoadCallbackA callback which is called when the load call takes long.
inContextA context for the callback.
Returns
Pointer to the newly created HttpConnection instance.
void Celartem::HttpManager::downloadFile ( const String inSaveFileName,
const String inUrl,
bool  inVerifyServer = false,
DuplicateStreamCallback  inLoadCallback = NULL,
void *  inContext = NULL 
)

Download a file from the specified location.
This function internally uses createHttpStorage method.

See Also
createHttpStorage
Parameters
inSaveFileNameFile name to save the file to.
inUrlURL of the resource to access. It should be escaped before passing to this method.
inVerifyServerWhether the server connected to should be verified or not.
inLoadCallbackCallback function called during fetching the data from the HTTP connection.
inContextContext used on the callback.
virtual CredentialProvider* Celartem::HttpManager::getCredentialProvider ( )
pure virtual

This function returns associated CredentialProvider instance.

Returns
Pointer to the CredentialProvider instance.
static String Celartem::HttpManager::getDefaultUserAgentName ( )
static

This method returns the default user agent name.

Returns
The default user agent name for the platform.
static String Celartem::HttpManager::getUserAgentPlatformSpec ( )
static

This method returns the user agent platform specifications, which is used in the default user agent name.

Returns
The user agent platform specifications.
virtual void Celartem::HttpManager::setProxy ( ProxyType  inType,
const String inHostName = "",
u16  inPort = 0 
)
pure virtual

This function changes the current settings for the HTTP proxy.

Parameters
inTypeOne of the ProxyType enumerations.
inHostNameAny string notation of the proxy server host; it is only required with proxyManual.
inPortPort number of the proxy server; it is only required with proxyManual.

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

Cuminas DjVu SDK 3.0.33103
This document is made with doxygen 1.8.5 at Sun Dec 15 2013 19:38:06.
Cuminas Logo