Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Poco::Net::HTTPClientSession Class Reference

#include <HTTPClientSession.h>

+ Inheritance diagram for Poco::Net::HTTPClientSession:
+ Collaboration diagram for Poco::Net::HTTPClientSession:

Classes

struct  ProxyConfig
 HTTP proxy server configuration. More...
 

Public Types

enum  ProxyAuthentication { PROXY_AUTH_NONE , PROXY_AUTH_HTTP_BASIC , PROXY_AUTH_HTTP_DIGEST , PROXY_AUTH_NTLM }
 
- Public Types inherited from Poco::Net::HTTPSession
enum  { HTTP_PORT = 80 }
 

Public Member Functions

 HTTPClientSession ()
 
 HTTPClientSession (const StreamSocket &socket)
 Creates an unconnected HTTPClientSession.
 
 HTTPClientSession (const SocketAddress &address)
 
 HTTPClientSession (const std::string &host, Poco::UInt16 port=HTTPSession::HTTP_PORT)
 Creates a HTTPClientSession using the given address.
 
 HTTPClientSession (const std::string &host, Poco::UInt16 port, const ProxyConfig &proxyConfig)
 Creates a HTTPClientSession using the given host and port.
 
virtual ~HTTPClientSession ()
 Creates a HTTPClientSession using the given host, port and proxy configuration.
 
void setHost (const std::string &host)
 
const std::string & getHost () const
 
void setPort (Poco::UInt16 port)
 Returns the host name of the target HTTP server.
 
Poco::UInt16 getPort () const
 
void setProxy (const std::string &host, Poco::UInt16 port=HTTPSession::HTTP_PORT)
 Returns the port number of the target HTTP server.
 
void setProxyHost (const std::string &host)
 Sets the proxy host name and port number.
 
void setProxyPort (Poco::UInt16 port)
 Sets the host name of the proxy server.
 
const std::string & getProxyHost () const
 Sets the port number of the proxy server.
 
Poco::UInt16 getProxyPort () const
 Returns the proxy host name.
 
void setProxyCredentials (const std::string &username, const std::string &password)
 Returns the proxy port number.
 
void setProxyUsername (const std::string &username)
 
const std::string & getProxyUsername () const
 
void setProxyPassword (const std::string &password)
 Returns the username for proxy authentication.
 
const std::string & getProxyPassword () const
 
void setProxyConfig (const ProxyConfig &config)
 Returns the password for proxy authentication.
 
const ProxyConfiggetProxyConfig () const
 Sets the proxy configuration.
 
void setKeepAliveTimeout (const Poco::Timespan &timeout)
 Returns the global proxy configuration.
 
const Poco::TimespangetKeepAliveTimeout () const
 Sets the connection timeout for HTTP connections.
 
virtual std::ostream & sendRequest (HTTPRequest &request)
 Returns the connection timeout for HTTP connections.
 
virtual std::istream & receiveResponse (HTTPResponse &response)
 
virtual bool peekResponse (HTTPResponse &response)
 
void flushRequest ()
 
void reset ()
 
virtual bool secure () const
 
bool bypassProxy () const
 
- Public Member Functions inherited from Poco::Net::HTTPSession
void setKeepAlive (bool keepAlive)
 
bool getKeepAlive () const
 
void setTimeout (const Poco::Timespan &timeout)
 
void setTimeout (const Poco::Timespan &connectionTimeout, const Poco::Timespan &sendTimeout, const Poco::Timespan &receiveTimeout)
 Sets the timeout for the HTTP session.
 
Poco::Timespan getTimeout () const
 Sets different timeouts for the HTTP session.
 
bool connected () const
 Returns the timeout for the HTTP session.
 
virtual void abort ()
 Returns true if the underlying socket is connected.
 
const Poco::ExceptionnetworkException () const
 
void attachSessionData (const Poco::Any &data)
 
const Poco::AnysessionData () const
 
StreamSocket detachSocket ()
 
StreamSocketsocket ()
 
void drainBuffer (Poco::Buffer< char > &buffer)
 Returns a reference to the underlying socket.
 

Static Public Member Functions

static void setGlobalProxyConfig (const ProxyConfig &config)
 Returns the proxy configuration.
 
static const ProxyConfiggetGlobalProxyConfig ()
 

Protected Types

enum  { DEFAULT_KEEP_ALIVE_TIMEOUT = 8 }
 

Protected Member Functions

void reconnect ()
 
int write (const char *buffer, std::streamsize length)
 Connects the underlying socket to the HTTP server.
 
std::ostream & sendRequestImpl (const HTTPRequest &request)
 Tries to re-connect if keep-alive is on.
 
virtual std::string proxyRequestPrefix () const
 Sends the given HTTPRequest over an existing connection.
 
virtual bool mustReconnect () const
 
virtual void proxyAuthenticate (HTTPRequest &request)
 Checks if we can reuse a persistent connection.
 
void proxyAuthenticateImpl (HTTPRequest &request, const ProxyConfig &proxyConfig)
 
void proxyAuthenticateDigest (HTTPRequest &request)
 
void proxyAuthenticateNTLM (HTTPRequest &request)
 Initiates a HTTP Digest authentication handshake with the proxy.
 
void sendChallengeRequest (const HTTPRequest &request, HTTPResponse &response)
 Initiates a HTTP NTLM authentication handshake with the proxy.
 
StreamSocket proxyConnect ()
 
void proxyTunnel ()
 
- Protected Member Functions inherited from Poco::Net::HTTPSession
 HTTPSession ()
 
 HTTPSession (const StreamSocket &socket)
 
 HTTPSession (const StreamSocket &socket, bool keepAlive)
 
virtual ~HTTPSession ()
 
int get ()
 
int peek ()
 
virtual int read (char *buffer, std::streamsize length)
 
int receive (char *buffer, int length)
 Writes data to the socket.
 
int buffered () const
 Reads up to length bytes.
 
void refill ()
 Returns the number of bytes in the buffer.
 
virtual void connect (const SocketAddress &address)
 Refills the internal buffer.
 
void attachSocket (const StreamSocket &socket)
 
void close ()
 
void setException (const Poco::Exception &exc)
 Closes the underlying socket.
 
void clearException ()
 Stores a clone of the exception.
 

Private Member Functions

 HTTPClientSession (const HTTPClientSession &)
 
HTTPClientSessionoperator= (const HTTPClientSession &)
 

Private Attributes

std::string _host
 
Poco::UInt16 _port
 
ProxyConfig _proxyConfig
 
Poco::Timespan _keepAliveTimeout
 
Poco::Timestamp _lastRequest
 
bool _reconnect
 
bool _mustReconnect
 
bool _expectResponseBody
 
bool _responseReceived
 
Poco::SharedPtr< std::ostream > _pRequestStream
 
Poco::SharedPtr< std::istream > _pResponseStream
 
HTTPBasicCredentials _proxyBasicCreds
 
HTTPDigestCredentials _proxyDigestCreds
 
HTTPNTLMCredentials _proxyNTLMCreds
 
bool _ntlmProxyAuthenticated
 

Static Private Attributes

static ProxyConfig _globalProxyConfig
 

Friends

class WebSocket
 

Detailed Description

This class implements the client-side of a HTTP session.

To send a HTTP request to a HTTP server, first instantiate a HTTPClientSession object and specify the server's host name and port number.

Then create a HTTPRequest object, fill it accordingly, and pass it as argument to the sendRequest() method.

sendRequest() will return an output stream that can be used to send the request body, if there is any.

After you are done sending the request body, create a HTTPResponse object and pass it to receiveResponse().

This will return an input stream that can be used to read the response body.

See RFC 2616 http://www.faqs.org/rfcs/rfc2616.html for more information about the HTTP protocol.

Proxies and proxy authorization (only HTTP Basic Authorization) is supported. Use setProxy() and setProxyCredentials() to set up a session through a proxy.

Definition at line 40 of file HTTPClientSession.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected

Returns true if the proxy should be bypassed for the current host.

Enumerator
DEFAULT_KEEP_ALIVE_TIMEOUT 

Definition at line 290 of file HTTPClientSession.h.

◆ ProxyAuthentication

Enumerator
PROXY_AUTH_NONE 
PROXY_AUTH_HTTP_BASIC 

No proxy authentication.

PROXY_AUTH_HTTP_DIGEST 

HTTP Basic proxy authentication (default, if username and password are supplied)

PROXY_AUTH_NTLM 

HTTP Digest proxy authentication.

NTLMv2 proxy authentication

Definition at line 68 of file HTTPClientSession.h.

Constructor & Destructor Documentation

◆ HTTPClientSession() [1/6]

Poco::Net::HTTPClientSession::HTTPClientSession ( )

◆ HTTPClientSession() [2/6]

Poco::Net::HTTPClientSession::HTTPClientSession ( const StreamSocket & socket)
explicit

Creates an unconnected HTTPClientSession.

◆ HTTPClientSession() [3/6]

Poco::Net::HTTPClientSession::HTTPClientSession ( const SocketAddress & address)
explicit

Creates a HTTPClientSession using the given socket. The socket must not be connected. The session takes ownership of the socket.

◆ HTTPClientSession() [4/6]

Poco::Net::HTTPClientSession::HTTPClientSession ( const std::string & host,
Poco::UInt16 port = HTTPSession::HTTP_PORT )

Creates a HTTPClientSession using the given address.

◆ HTTPClientSession() [5/6]

Poco::Net::HTTPClientSession::HTTPClientSession ( const std::string & host,
Poco::UInt16 port,
const ProxyConfig & proxyConfig )

Creates a HTTPClientSession using the given host and port.

◆ ~HTTPClientSession()

virtual Poco::Net::HTTPClientSession::~HTTPClientSession ( )
virtual

Creates a HTTPClientSession using the given host, port and proxy configuration.

◆ HTTPClientSession() [6/6]

Poco::Net::HTTPClientSession::HTTPClientSession ( const HTTPClientSession & )
private

Member Function Documentation

◆ bypassProxy()

bool Poco::Net::HTTPClientSession::bypassProxy ( ) const

Return true iff the session uses SSL or TLS, or false otherwise.

◆ flushRequest()

void Poco::Net::HTTPClientSession::flushRequest ( )

If the request contains a "Expect: 100-continue" header, (see HTTPRequest::setExpectContinue()) this method can be used to check whether the server has sent a 100 Continue response before continuing with the request, i.e. sending the request body, after calling sendRequest().

Returns true if the server has responded with 100 Continue, otherwise false. The HTTPResponse object contains the response sent by the server.

In any case, receiveResponse() must be called afterwards as well in order to complete the request. The same HTTPResponse object passed to peekResponse() must also be passed to receiveResponse().

This method should only be called if the request contains a "Expect: 100-continue" header.

◆ getGlobalProxyConfig()

const HTTPClientSession::ProxyConfig & Poco::Net::HTTPClientSession::getGlobalProxyConfig ( )
inlinestatic

Sets the global proxy configuration.

The global proxy configuration is used by all HTTPClientSession instances, unless a different proxy configuration is explicitly set.

Warning: Setting the global proxy configuration is not thread safe. The global proxy configuration should be set at start up, before the first HTTPClientSession instance is created.

Definition at line 408 of file HTTPClientSession.h.

◆ getHost()

const std::string & Poco::Net::HTTPClientSession::getHost ( ) const
inline

Sets the host name of the target HTTP server.

The host must not be changed once there is an open connection to the server.

Definition at line 366 of file HTTPClientSession.h.

◆ getKeepAliveTimeout()

const Poco::Timespan & Poco::Net::HTTPClientSession::getKeepAliveTimeout ( ) const
inline

Sets the connection timeout for HTTP connections.

Definition at line 414 of file HTTPClientSession.h.

◆ getPort()

Poco::UInt16 Poco::Net::HTTPClientSession::getPort ( ) const
inline

Sets the port number of the target HTTP server.

The port number must not be changed once there is an open connection to the server.

Definition at line 372 of file HTTPClientSession.h.

◆ getProxyConfig()

const HTTPClientSession::ProxyConfig & Poco::Net::HTTPClientSession::getProxyConfig ( ) const
inline

Sets the proxy configuration.

Definition at line 402 of file HTTPClientSession.h.

◆ getProxyHost()

const std::string & Poco::Net::HTTPClientSession::getProxyHost ( ) const
inline

Sets the port number of the proxy server.

Definition at line 378 of file HTTPClientSession.h.

◆ getProxyPassword()

const std::string & Poco::Net::HTTPClientSession::getProxyPassword ( ) const
inline

Sets the password for proxy authentication. Only Basic authentication is supported.

Definition at line 396 of file HTTPClientSession.h.

◆ getProxyPort()

Poco::UInt16 Poco::Net::HTTPClientSession::getProxyPort ( ) const
inline

Returns the proxy host name.

Definition at line 384 of file HTTPClientSession.h.

◆ getProxyUsername()

const std::string & Poco::Net::HTTPClientSession::getProxyUsername ( ) const
inline

Sets the username for proxy authentication. Only Basic authentication is supported.

Definition at line 390 of file HTTPClientSession.h.

◆ mustReconnect()

virtual bool Poco::Net::HTTPClientSession::mustReconnect ( ) const
protectedvirtual

Returns the prefix prepended to the URI for proxy requests (e.g., "http://myhost.com").

◆ operator=()

HTTPClientSession & Poco::Net::HTTPClientSession::operator= ( const HTTPClientSession & )
private

◆ peekResponse()

virtual bool Poco::Net::HTTPClientSession::peekResponse ( HTTPResponse & response)
virtual

Receives the header for the response to the previous HTTP request.

The returned input stream can be used to read the response body. The stream is valid until sendRequest() is called or the session is destroyed.

It must be ensured that the response stream is fully consumed before sending a new request and persistent connections are enabled. Otherwise, the unread part of the response body may be treated as part of the next request's response header, resulting in a Poco::Net::MessageException being thrown.

In case a network or server failure happens while reading the response body from the returned stream, the stream state will change to bad or fail. In this case, reset() should be called if the session will be reused and persistent connections are enabled to ensure a new connection will be set up for the next request.

◆ proxyAuthenticate()

virtual void Poco::Net::HTTPClientSession::proxyAuthenticate ( HTTPRequest & request)
protectedvirtual

Checks if we can reuse a persistent connection.

Reimplemented in Poco::Net::HTTPSClientSession.

◆ proxyAuthenticateDigest()

void Poco::Net::HTTPClientSession::proxyAuthenticateDigest ( HTTPRequest & request)
protected

Sets the proxy credentials (Proxy-Authorization header), if proxy username and password have been set.

◆ proxyAuthenticateImpl()

void Poco::Net::HTTPClientSession::proxyAuthenticateImpl ( HTTPRequest & request,
const ProxyConfig & proxyConfig )
protected

Sets the proxy credentials (Proxy-Authorization header), if proxy username and password have been set.

◆ proxyAuthenticateNTLM()

void Poco::Net::HTTPClientSession::proxyAuthenticateNTLM ( HTTPRequest & request)
protected

Initiates a HTTP Digest authentication handshake with the proxy.

◆ proxyConnect()

StreamSocket Poco::Net::HTTPClientSession::proxyConnect ( )
protected

Sends a probe request for Digest and NTLM authentication to obtain the server challenge.

◆ proxyRequestPrefix()

virtual std::string Poco::Net::HTTPClientSession::proxyRequestPrefix ( ) const
protectedvirtual

Sends the given HTTPRequest over an existing connection.

Reimplemented in Poco::Net::HTTPSClientSession.

◆ proxyTunnel()

void Poco::Net::HTTPClientSession::proxyTunnel ( )
protected

Sends a CONNECT request to the proxy server and returns a StreamSocket for the resulting connection.

◆ receiveResponse()

virtual std::istream & Poco::Net::HTTPClientSession::receiveResponse ( HTTPResponse & response)
virtual

Sends the header for the given HTTP request to the server.

The HTTPClientSession will set the request's Host and Keep-Alive headers accordingly.

The returned output stream can be used to write the request body. The stream is valid until receiveResponse() is called or the session is destroyed.

In case a network or server failure happens while writing the request body to the returned stream, the stream state will change to bad or fail. In this case, reset() should be called if the session will be reused and persistent connections are enabled to ensure a new connection will be set up for the next request.

+ Here is the caller graph for this function:

◆ reconnect()

void Poco::Net::HTTPClientSession::reconnect ( )
protected

◆ reset()

void Poco::Net::HTTPClientSession::reset ( )

Flushes the request stream.

Normally this method does not need to be called. It can be used to ensure the request has been fully sent if receiveResponse() is not called, e.g., because the underlying socket will be detached.

◆ secure()

virtual bool Poco::Net::HTTPClientSession::secure ( ) const
virtual

Resets the session and closes the socket.

The next request will initiate a new connection, even if persistent connections are enabled.

This should be called whenever something went wrong when sending a request (e.g., sendRequest() or receiveResponse() throws an exception, or the request or response stream changes into fail or bad state, but not eof state).

Reimplemented in Poco::Net::HTTPSClientSession.

◆ sendChallengeRequest()

void Poco::Net::HTTPClientSession::sendChallengeRequest ( const HTTPRequest & request,
HTTPResponse & response )
protected

Initiates a HTTP NTLM authentication handshake with the proxy.

◆ sendRequest()

virtual std::ostream & Poco::Net::HTTPClientSession::sendRequest ( HTTPRequest & request)
virtual

Returns the connection timeout for HTTP connections.

+ Here is the caller graph for this function:

◆ sendRequestImpl()

std::ostream & Poco::Net::HTTPClientSession::sendRequestImpl ( const HTTPRequest & request)
protected

Tries to re-connect if keep-alive is on.

◆ setGlobalProxyConfig()

static void Poco::Net::HTTPClientSession::setGlobalProxyConfig ( const ProxyConfig & config)
static

Returns the proxy configuration.

◆ setHost()

void Poco::Net::HTTPClientSession::setHost ( const std::string & host)

Destroys the HTTPClientSession and closes the underlying socket.

◆ setKeepAliveTimeout()

void Poco::Net::HTTPClientSession::setKeepAliveTimeout ( const Poco::Timespan & timeout)

Returns the global proxy configuration.

◆ setPort()

void Poco::Net::HTTPClientSession::setPort ( Poco::UInt16 port)

Returns the host name of the target HTTP server.

◆ setProxy()

void Poco::Net::HTTPClientSession::setProxy ( const std::string & host,
Poco::UInt16 port = HTTPSession::HTTP_PORT )

Returns the port number of the target HTTP server.

◆ setProxyConfig()

void Poco::Net::HTTPClientSession::setProxyConfig ( const ProxyConfig & config)

Returns the password for proxy authentication.

◆ setProxyCredentials()

void Poco::Net::HTTPClientSession::setProxyCredentials ( const std::string & username,
const std::string & password )

Returns the proxy port number.

◆ setProxyHost()

void Poco::Net::HTTPClientSession::setProxyHost ( const std::string & host)

Sets the proxy host name and port number.

◆ setProxyPassword()

void Poco::Net::HTTPClientSession::setProxyPassword ( const std::string & password)

Returns the username for proxy authentication.

◆ setProxyPort()

void Poco::Net::HTTPClientSession::setProxyPort ( Poco::UInt16 port)

Sets the host name of the proxy server.

◆ setProxyUsername()

void Poco::Net::HTTPClientSession::setProxyUsername ( const std::string & username)

Sets the username and password for proxy authentication. Only Basic authentication is supported.

◆ write()

int Poco::Net::HTTPClientSession::write ( const char * buffer,
std::streamsize length )
protectedvirtual

Connects the underlying socket to the HTTP server.

Reimplemented from Poco::Net::HTTPSession.

Friends And Related Symbol Documentation

◆ WebSocket

friend class WebSocket
friend

Definition at line 359 of file HTTPClientSession.h.

Member Data Documentation

◆ _expectResponseBody

bool Poco::Net::HTTPClientSession::_expectResponseBody
private

Definition at line 345 of file HTTPClientSession.h.

◆ _globalProxyConfig

ProxyConfig Poco::Net::HTTPClientSession::_globalProxyConfig
staticprivate

Definition at line 354 of file HTTPClientSession.h.

◆ _host

std::string Poco::Net::HTTPClientSession::_host
private

Calls proxyConnect() and attaches the resulting StreamSocket to the HTTPClientSession.

Definition at line 338 of file HTTPClientSession.h.

◆ _keepAliveTimeout

Poco::Timespan Poco::Net::HTTPClientSession::_keepAliveTimeout
private

Definition at line 341 of file HTTPClientSession.h.

◆ _lastRequest

Poco::Timestamp Poco::Net::HTTPClientSession::_lastRequest
private

Definition at line 342 of file HTTPClientSession.h.

◆ _mustReconnect

bool Poco::Net::HTTPClientSession::_mustReconnect
private

Definition at line 344 of file HTTPClientSession.h.

◆ _ntlmProxyAuthenticated

bool Poco::Net::HTTPClientSession::_ntlmProxyAuthenticated
private

Definition at line 352 of file HTTPClientSession.h.

◆ _port

Poco::UInt16 Poco::Net::HTTPClientSession::_port
private

Definition at line 339 of file HTTPClientSession.h.

◆ _pRequestStream

Poco::SharedPtr<std::ostream> Poco::Net::HTTPClientSession::_pRequestStream
private

Definition at line 347 of file HTTPClientSession.h.

◆ _pResponseStream

Poco::SharedPtr<std::istream> Poco::Net::HTTPClientSession::_pResponseStream
private

Definition at line 348 of file HTTPClientSession.h.

◆ _proxyBasicCreds

HTTPBasicCredentials Poco::Net::HTTPClientSession::_proxyBasicCreds
private

Definition at line 349 of file HTTPClientSession.h.

◆ _proxyConfig

ProxyConfig Poco::Net::HTTPClientSession::_proxyConfig
private

Definition at line 340 of file HTTPClientSession.h.

◆ _proxyDigestCreds

HTTPDigestCredentials Poco::Net::HTTPClientSession::_proxyDigestCreds
private

Definition at line 350 of file HTTPClientSession.h.

◆ _proxyNTLMCreds

HTTPNTLMCredentials Poco::Net::HTTPClientSession::_proxyNTLMCreds
private

Definition at line 351 of file HTTPClientSession.h.

◆ _reconnect

bool Poco::Net::HTTPClientSession::_reconnect
private

Definition at line 343 of file HTTPClientSession.h.

◆ _responseReceived

bool Poco::Net::HTTPClientSession::_responseReceived
private

Definition at line 346 of file HTTPClientSession.h.


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