Ark Server API (ASE) - Wiki
|
#include <HTTPClientSession.h>
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 ProxyConfig & | getProxyConfig () const |
Sets the proxy configuration. | |
void | setKeepAliveTimeout (const Poco::Timespan &timeout) |
Returns the global proxy configuration. | |
const Poco::Timespan & | getKeepAliveTimeout () 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::Exception * | networkException () const |
void | attachSessionData (const Poco::Any &data) |
const Poco::Any & | sessionData () const |
StreamSocket | detachSocket () |
StreamSocket & | socket () |
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 ProxyConfig & | getGlobalProxyConfig () |
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 &) | |
HTTPClientSession & | operator= (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 |
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.
|
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.
Definition at line 68 of file HTTPClientSession.h.
Poco::Net::HTTPClientSession::HTTPClientSession | ( | ) |
|
explicit |
Creates an unconnected HTTPClientSession.
|
explicit |
Creates a HTTPClientSession using the given socket. The socket must not be connected. The session takes ownership of the socket.
Poco::Net::HTTPClientSession::HTTPClientSession | ( | const std::string & | host, |
Poco::UInt16 | port = HTTPSession::HTTP_PORT ) |
Creates a HTTPClientSession using the given address.
Poco::Net::HTTPClientSession::HTTPClientSession | ( | const std::string & | host, |
Poco::UInt16 | port, | ||
const ProxyConfig & | proxyConfig ) |
Creates a HTTPClientSession using the given host and port.
|
virtual |
Creates a HTTPClientSession using the given host, port and proxy configuration.
|
private |
bool Poco::Net::HTTPClientSession::bypassProxy | ( | ) | const |
Return true iff the session uses SSL or TLS, or false otherwise.
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.
|
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.
|
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.
|
inline |
Sets the connection timeout for HTTP connections.
Definition at line 414 of file HTTPClientSession.h.
|
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.
|
inline |
Sets the proxy configuration.
Definition at line 402 of file HTTPClientSession.h.
|
inline |
Sets the port number of the proxy server.
Definition at line 378 of file HTTPClientSession.h.
|
inline |
Sets the password for proxy authentication. Only Basic authentication is supported.
Definition at line 396 of file HTTPClientSession.h.
|
inline |
Returns the proxy host name.
Definition at line 384 of file HTTPClientSession.h.
|
inline |
Sets the username for proxy authentication. Only Basic authentication is supported.
Definition at line 390 of file HTTPClientSession.h.
|
protectedvirtual |
Returns the prefix prepended to the URI for proxy requests (e.g., "http://myhost.com").
|
private |
|
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.
|
protectedvirtual |
Checks if we can reuse a persistent connection.
Reimplemented in Poco::Net::HTTPSClientSession.
|
protected |
Sets the proxy credentials (Proxy-Authorization header), if proxy username and password have been set.
|
protected |
Sets the proxy credentials (Proxy-Authorization header), if proxy username and password have been set.
|
protected |
Initiates a HTTP Digest authentication handshake with the proxy.
|
protected |
Sends a probe request for Digest and NTLM authentication to obtain the server challenge.
|
protectedvirtual |
Sends the given HTTPRequest over an existing connection.
Reimplemented in Poco::Net::HTTPSClientSession.
|
protected |
Sends a CONNECT request to the proxy server and returns a StreamSocket for the resulting connection.
|
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.
|
protected |
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.
|
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.
|
protected |
Initiates a HTTP NTLM authentication handshake with the proxy.
|
virtual |
Returns the connection timeout for HTTP connections.
|
protected |
Tries to re-connect if keep-alive is on.
|
static |
Returns the proxy configuration.
void Poco::Net::HTTPClientSession::setHost | ( | const std::string & | host | ) |
Destroys the HTTPClientSession and closes the underlying socket.
void Poco::Net::HTTPClientSession::setKeepAliveTimeout | ( | const Poco::Timespan & | timeout | ) |
Returns the global proxy configuration.
void Poco::Net::HTTPClientSession::setPort | ( | Poco::UInt16 | port | ) |
Returns the host name of the target HTTP server.
void Poco::Net::HTTPClientSession::setProxy | ( | const std::string & | host, |
Poco::UInt16 | port = HTTPSession::HTTP_PORT ) |
Returns the port number of the target HTTP server.
void Poco::Net::HTTPClientSession::setProxyConfig | ( | const ProxyConfig & | config | ) |
Returns the password for proxy authentication.
void Poco::Net::HTTPClientSession::setProxyCredentials | ( | const std::string & | username, |
const std::string & | password ) |
Returns the proxy port number.
void Poco::Net::HTTPClientSession::setProxyHost | ( | const std::string & | host | ) |
Sets the proxy host name and port number.
void Poco::Net::HTTPClientSession::setProxyPassword | ( | const std::string & | password | ) |
Returns the username for proxy authentication.
void Poco::Net::HTTPClientSession::setProxyPort | ( | Poco::UInt16 | port | ) |
Sets the host name of the proxy server.
void Poco::Net::HTTPClientSession::setProxyUsername | ( | const std::string & | username | ) |
Sets the username and password for proxy authentication. Only Basic authentication is supported.
|
protectedvirtual |
Connects the underlying socket to the HTTP server.
Reimplemented from Poco::Net::HTTPSession.
|
friend |
Definition at line 359 of file HTTPClientSession.h.
|
private |
Definition at line 345 of file HTTPClientSession.h.
|
staticprivate |
Definition at line 354 of file HTTPClientSession.h.
|
private |
Calls proxyConnect() and attaches the resulting StreamSocket to the HTTPClientSession.
Definition at line 338 of file HTTPClientSession.h.
|
private |
Definition at line 341 of file HTTPClientSession.h.
|
private |
Definition at line 342 of file HTTPClientSession.h.
|
private |
Definition at line 344 of file HTTPClientSession.h.
|
private |
Definition at line 352 of file HTTPClientSession.h.
|
private |
Definition at line 339 of file HTTPClientSession.h.
|
private |
Definition at line 347 of file HTTPClientSession.h.
|
private |
Definition at line 348 of file HTTPClientSession.h.
|
private |
Definition at line 349 of file HTTPClientSession.h.
|
private |
Definition at line 340 of file HTTPClientSession.h.
|
private |
Definition at line 350 of file HTTPClientSession.h.
|
private |
Definition at line 351 of file HTTPClientSession.h.
|
private |
Definition at line 343 of file HTTPClientSession.h.
|
private |
Definition at line 346 of file HTTPClientSession.h.