Celartem::HttpManager Class Reference

#include <cel_http.h>

Inheritance diagram for Celartem::HttpManager:

Inheritance graph
[legend]

List of all members.

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

Static Public Member Functions

static AutoPtr< HttpManagercreate (const String &inUserAgentName=NullString, CredentialProvider *inCredentialProvider=NULL)
static String getDefaultUserAgentName ()
static String getUserAgentPlatformSpec ()


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

Definition at line 101 of file cel_http.h.


Member Function Documentation

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:
inHostName It 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.
inPort It 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<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:
inHostName It 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.
inPort It specifies the port to connect. HTTPS (Secure HTTP connection) uses 443 by default. 0 to use the default (443).
inVerifyServer Whether the server connected to should be verified or not.
inLoadCallback A callback which is called when the load call takes long.
inContext A context for the callback.
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:
inUrl URL of the resource to access. It should be escaped before passing to this method.
inVerifyServer Whether the server connected to should be verified or not.
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 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:
inType One of the ProxyType enumerations.
inHostName Any string notation of the proxy server host; it is only required with proxyManual.
inPort Port number of the proxy server; it is only required with proxyManual.

virtual CredentialProvider* Celartem::HttpManager::getCredentialProvider (  )  [pure virtual]

This function returns associated CredentialProvider instance.

Returns:
Pointer to the CredentialProvider instance.

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:
inUserAgentName User Agent Name for your application. If this value is not specified (or NullString), it uses system default.
inCredentialProvider Pointer to a class instance to get credential information.
Returns:
Pointer to the newly created HttpManager 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.


The documentation for this class was generated from the following file:
This document is automatically generated using doxygen 1.5.4 at Fri Jun 27 18:23:17 2008.