AbstractHttpConnection Class Reference

Abstract class, it's a common interface for HTTPConnection classes. More...

#include <AbstractHttpConnection.h>

List of all members.

Public Types

enum  RequestMethod { MethodGet, MethodPost, MethodPut, MethodHead }
 These are the possible request methods.
enum  ConnectionStatus {
  StatusNoError = 0, StatusCancelledByUser = -1, StatusInternalError = -2, StatusReadingError = -3,
  StatusWritingError = -4, StatusInvalidParam = -5
}

Public Member Functions

 AbstractHttpConnection (const char *ua)
 Sets defaults, sets the userAgent.
virtual int open (const URL &url, RequestMethod method=MethodPost)=0
 Open the connection to the given url.
virtual int close ()=0
 This method closes this connection.
void setRequestMethod (RequestMethod method)
 Set the request method for the URL request, one of RequestMethod enum.
virtual int request (InputStream &data, OutputStream &response)=0
 Sends the request.
virtual void setRequestHeader (const char *key, const char *value)
 Sets the general request property.
virtual StringBuffer getResponseHeader (const char *key)
 Returns the value of the named response header field.
virtual void setAuthentication (HttpAuthentication *auth)
 Sets the authentication object.
void setChunkSize (const int size)
 Sets the max chunk size, for HTTP request (outgoing data is chunked).
int getChunkSize ()
virtual void setURL (const URL &newURL)
 Change the URL the subsequent calls to setMessage() should use as target url.
virtual const URL & getURL () const
 Returns the url.
virtual void setTimeout (unsigned int t)
 Sets the connection timeout.
virtual unsigned int getTimeout () const
 Returns the connection timeout.
virtual bool getSSLVerifyServer () const
 Enabled by default: the client refuses to establish the connection unless the server presents a valid certificate.
virtual void setSSLVerifyServer (bool value)
virtual bool getSSLVerifyHost () const
 Enabled by default: the client refuses to establish the connection unless the server's certificate matches its host name.
virtual void setSSLVerifyHost (bool value)
virtual bool getCompression () const
 Enable HTTP compression.
virtual void setCompression (bool value)
virtual void setKeepAlive (bool val)
 Sets the keep-alive flag: the connection is not dropped on destructor.

Protected Attributes

URL url
RequestMethod method
StringMap requestHeaders
 The property-value map of headers to send.
StringMap responseHeaders
 The property-value map of headers received.
HttpAuthentication * auth
 The HTTP authentication. Auth type can be Basic or Digest.
int chunkSize
 Max chunk size for http requests, in bytes.
Proxy proxy
unsigned int timeout
StringBuffer userAgent
StringBuffer SSLServerCertificates
bool SSLVerifyServer
bool SSLVerifyHost
bool compression_enabled
bool keepalive
 If set to true, the connection is not dropped on destructor.


Detailed Description

Abstract class, it's a common interface for HTTPConnection classes.

It rapresents a generic class to manage HTTP connections, so it has methods to open a connection, close it, and make HTTP requests (GET, PUT, POST). There is an implementation of this interface for each platform (HTTPConnection) since the APIs to manage HTTP connections are low level.

The caller should first open the connection via the method open(), specify the request method, and then send the request calling request() method. The response is returned in the outputStream passed. If the request method is not specified, the default is POST.

Request headers can be set easily with the method setRequestHeader(). The headers returned in the response are available after the request completion, calling the method getResponseHeader().


Member Function Documentation

virtual int AbstractHttpConnection::close (  )  [pure virtual]

This method closes this connection.

It does not close the corresponding input and output stream which need to be closed separately (if they were previously opened)

virtual StringBuffer AbstractHttpConnection::getResponseHeader ( const char *  key  )  [inline, virtual]

Returns the value of the named response header field.

Parameters:
key name of a header field.
Returns:
the value of the named header field, or NULL string if there is no such field in the header.

References responseHeaders.

virtual bool AbstractHttpConnection::getSSLVerifyHost (  )  const [inline, virtual]

Enabled by default: the client refuses to establish the connection unless the server's certificate matches its host name.

In cases where the certificate still seems to be valid it might make sense to disable this option and allow such connections.

virtual bool AbstractHttpConnection::getSSLVerifyServer (  )  const [inline, virtual]

Enabled by default: the client refuses to establish the connection unless the server presents a valid certificate.

Disabling this option considerably reduces the security of SSL (man-in-the-middle attacks become possible) and is not recommended.

virtual int AbstractHttpConnection::open ( const URL &  url,
RequestMethod  method = MethodPost 
) [pure virtual]

Open the connection to the given url.

Parameters:
url the connection url
method (optional) the request method, one of RequestMethod enum

virtual int AbstractHttpConnection::request ( InputStream &  data,
OutputStream &  response 
) [pure virtual]

Sends the request.

The method used must be set via setRequestMethod (default = POST). The headers/authentication must already be set before calling this method (otherwise none is used).

Parameters:
data the data to be sent
response the response returned
Returns:
the HTTP Status Code returned or -1 if no status code can be discerned.

virtual void AbstractHttpConnection::setAuthentication ( HttpAuthentication *  auth  )  [inline, virtual]

Sets the authentication object.

The HttpConnection will only use authentication if this object is not NULL.

Parameters:
auth The authentication object to use.

virtual void AbstractHttpConnection::setKeepAlive ( bool  val  )  [inline, virtual]

Sets the keep-alive flag: the connection is not dropped on destructor.

Note: on some platforms this is not applicable, so it's just ignored.

References keepalive.

virtual void AbstractHttpConnection::setRequestHeader ( const char *  key,
const char *  value 
) [inline, virtual]

Sets the general request property.

If a property with the key already exists, overwrite its value with the new value.

NOTE: HTTP requires all request properties which can legally have multiple instances with the same key to use a comma-seperated list syntax which enables multiple properties to be appended into a single property.

Parameters:
key the keyword by which the request is known (e.g., "Accept").
value the value associated with it.

References requestHeaders.

void AbstractHttpConnection::setRequestMethod ( RequestMethod  method  )  [inline]

Set the request method for the URL request, one of RequestMethod enum.

are legal, subject to protocol restrictions. The default method is POST.

virtual void AbstractHttpConnection::setTimeout ( unsigned int  t  )  [inline, virtual]

Sets the connection timeout.

Parameters:
t the new timeout in seconds

virtual void AbstractHttpConnection::setURL ( const URL &  newURL  )  [inline, virtual]

Change the URL the subsequent calls to setMessage() should use as target url.

Parameters:
url the new target url


Member Data Documentation

If set to true, the connection is not dropped on destructor.

Default = false. Note: on some platforms this is not applicable, so it's just ignored.

Referenced by AbstractHttpConnection(), and setKeepAlive().


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

Generated on Tue Aug 3 09:56:47 2010 for Funambol Outlook Plug-in Library by  doxygen 1.5.7.1