SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Protected Member Functions
RWHttpClient Class Reference

Provides a low-level interface for communicating with an HTTP server. More...

#include <rw/http/RWHttpClient.h>

Inheritance diagram for RWHttpClient:
RWHandleBase RWHttpSocketClient RWHttpsSecureSocketClient

Public Member Functions

 RWHttpClient (void)
 
 RWHttpClient (const RWHttpClient &client)
 
virtual ~RWHttpClient ()
 
void connect (const RWSockAddrBase &address, unsigned long maxwait=0)
 
RWHttpReply getReply (unsigned long maxwait=0)
 
RWHttpReply getReply (RWTFunctor< void(RWPortal)> handler, unsigned long maxwait=0)
 
RWHttpReply getReply (RWTFunctor< void(RWPortal, RWHttpReply &)> handler, unsigned long maxwait=0)
 
bool isConnected () const
 
RWHttpClientoperator= (const RWHttpClient &other)
 
bool submit (RWHttpRequest request, RWHttpPipeline pl=RW_HTTP_FORBID_PIPELINING, unsigned long maxwait=0)
 
- Public Member Functions inherited from RWHandleBase
bool isValid (void) const
 
bool operator!= (const RWHandleBase &second) const
 
bool operator< (const RWHandleBase &second) const
 
bool operator== (const RWHandleBase &second) const
 

Protected Member Functions

 RWHttpClient (RWHttpClientImp *imp)
 
RWHttpClientImp & body () const
 
- Protected Member Functions inherited from RWHandleBase
 RWHandleBase (void)
 
 RWHandleBase (RWStaticCtor)
 
 RWHandleBase (RWBodyBase *body)
 
 RWHandleBase (const RWHandleBase &second)
 
 ~RWHandleBase (void)
 
RWBodyBasebody (void) const
 
RWHandleBaseoperator= (const RWHandleBase &second)
 

Detailed Description

RWHttpClient enables detailed control over HTTP communications. The asynchronous nature of HTTP/1.1 enables you to submit multiple requests to the server before retrieving any of the replies. Replies are returned in the same order that they are submitted.

RWHttpClient objects are lightweight. They are implemented using the handle-body pattern. The RWHttpClient is a handle to an implementation that performs the protocol interaction.

Constructor & Destructor Documentation

RWHttpClient::RWHttpClient ( RWHttpClientImp *  imp)
inlineprotected

Protected constructor from imp.

RWHttpClient::RWHttpClient ( void  )
inline

Constructs a default RWHttpClient object.

RWHttpClient::RWHttpClient ( const RWHttpClient client)
inline

Copy constructor. The body of the new client is the same as client.

virtual RWHttpClient::~RWHttpClient ( )
virtual

Virtual destructor.

Member Function Documentation

RWHttpClientImp & RWHttpClient::body ( void  ) const
inlineprotected

Returns a reference to the body.

void RWHttpClient::connect ( const RWSockAddrBase address,
unsigned long  maxwait = 0 
)
inline

Enables an HTTP client to establish a connection session with an HTTP server. The address argument specifies the address of the server to connect to.

The optional value maxwait specifies how long the RWHttpClient waits for data to become available on a socket before deciding that the socket is dead. maxwait defaults to 0, which specifies that RWHttpClient waits indefinitely for data. If the maxwait time expires, an RWNetOperationTimeoutError exception is thrown.

Note
A timeout may take longer to complete than the timeout specified if address was not prepared (RWSockAddr::prepare()) prior to this call. RWSockAddr::prepare() is called internally and may block indefinitely in gethostbyname() when attempting to determine the IP address.
RWHttpReply RWHttpClient::getReply ( unsigned long  maxwait = 0)
inline

Returns the next response from the server. The response contains the status code and headers, plus the body of the response as an RWCString.

The optional value maxwait is the number of milliseconds that the RWHttpClient waits for data to become available on a socket before deciding that the socket is dead. maxwait defaults to 0, which specifies that RWHttpClient waits indefinitely for data. If the maxwait time expires, an RWNetOperationTimeoutError exception is thrown.

RWHttpReply RWHttpClient::getReply ( RWTFunctor< void(RWPortal)>  handler,
unsigned long  maxwait = 0 
)
inline

Returns the next reply from the server. The reply contains the status code and headers for the reply. A portal containing the body of the message is passed to the user-defined handler. If the message is not read fully from the portal by the handler, an RWHttpHandlerError exception is thrown.

The optional value maxwait is the number of milliseconds that the RWHttpClient waits for data to become available on a socket before deciding that the socket is dead. maxwait defaults to 0, which specifies that RWHttpClient waits indefinitely for data. If the maxwait time expires, an RWNetOperationTimeoutError exception is thrown.

RWHttpReply RWHttpClient::getReply ( RWTFunctor< void(RWPortal, RWHttpReply &)>  handler,
unsigned long  maxwait = 0 
)
inline

Equivalent to getReply(RWTFunctor<void(RWPortal)>, unsigned long), however this method also receives a reference to the RWHttpReply instance that is returned when the function completes. This method allows the user to access the headers and status of the message while processing the body.

bool RWHttpClient::isConnected ( ) const
inline

Returns true if the client was last known to be connected to an HTTP server. Otherwise returns false.

A return of true does not guarantee that the client is currently connected to the server. true indicates only the state of the connection after the last read or write attempt. For example, if the server silently closed the connection, this function returns true.

RWHttpClient & RWHttpClient::operator= ( const RWHttpClient other)
inline

Assigns the body of other to this. Any previous bodies associated with this RWHttpClient object are released.

bool RWHttpClient::submit ( RWHttpRequest  request,
RWHttpPipeline  pl = RW_HTTP_FORBID_PIPELINING,
unsigned long  maxwait = 0 
)
inline

Returns true if it successfully submits a request to the server. Otherwise returns false. If pl is equal to RW_HTTP_ALLOW_PIPELINING, the client assumes that it is safe to pipeline the request. For information about pipelining, see the Internet Protocols Module User's Guide.

The optional value maxwait is the number of milliseconds that the RWHttpClient waits for data to become available on a socket before deciding that the socket is dead. maxwait defaults to 0, which specifies that RWHttpClient waits indefinitely for data. If the maxwait time expires, an RWNetOperationTimeoutError exception is thrown.

Copyright © 2022 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.