#include <OW_HTTPClient.hpp>
Inheritance diagram for OW_NAMESPACE::HTTPClient:
Public Member Functions | |
HTTPClient (const String &url, const SSLClientCtxRef &sslCtx=SSLClientCtxRef()) | |
Creates an httpClient object. | |
virtual | ~HTTPClient () |
virtual Reference< std::iostream > | beginRequest (const String &methodName, const String &cimObject) |
virtual CIMProtocolIStreamIFCRef | endRequest (const Reference< std::iostream > &request, const String &methodName, const String &cimObject, ERequestType requestType, const String &cimProtocolVersion) |
Establishes a connection (if not already connected) to the CIMOM and sends a request. | |
virtual CIMFeatures | getFeatures () |
Sends an OPTIONS request to the HTTP server, and reports the results. | |
SocketAddress | getLocalAddress () const |
Gets the address of the local machine. | |
SocketAddress | getPeerAddress () const |
Gets the address of the peer connection. | |
void | setHTTPPath (const String &newPath) |
Set the HTTP path to use. | |
void | assumeBasicAuth () |
After calling this function, the next request will (re)connect and send credentials using basic authentication. | |
virtual void | close () |
Close the connetion to the CIMOM. | |
void | addCustomHeader (const String &name, const String &value) |
Add a custom header to add to requests. | |
bool | getResponseHeader (const String &hdrName, String &valueOut) const |
Retrieve a given header value from the server response. | |
virtual void | setReceiveTimeout (int seconds) |
Set the receive timeout on the socket. | |
virtual int | getReceiveTimeout () const |
Get the receive timeout. | |
virtual void | setSendTimeout (int seconds) |
Set the send timeout on the socket. | |
virtual int | getSendTimeout () const |
Get the send timeout. | |
virtual void | setConnectTimeout (int seconds) |
Set the connect timeout on the socket. | |
virtual int | getConnectTimeout () const |
Get the connect timeout. | |
virtual void | setTimeouts (int seconds) |
Set all timeouts (send, receive, connect). | |
Static Public Attributes | |
static const int | INFINITE_TIMEOUT = -1 |
Private Types | |
enum | Resp_t { FATAL, RETRY, GOOD, CONTINUE } |
enum | EStatusLineSummary { E_STATUS_GOOD, E_STATUS_ERROR } |
if the server has disconnected or sent us something since our last request (remember connections are persistent), we need to process it *before* we send another request, or if we get something while we are sending, we need to look at the header to know if we should keep sending data. More... | |
Private Member Functions | |
void | setUrl () |
void | cleanUpIStreams () |
void | receiveAuthentication () |
void | sendAuthorization () |
bool | receiveOptions (void) |
bool | headerHasKey (const String &key) |
String | getHeaderValue (const String &key) |
void | addHeaderCommon (const String &key, const String &value) |
void | addHeaderPersistent (const String &key, const String &value) |
void | addHeaderNew (const String &key, const String &value) |
void | sendHeaders (const String &method, const String &prot) |
Resp_t | processHeaders (String &reasonPhrase) |
precondition: m_statusLine is set to the status line, and the headers have been read | |
CIMProtocolIStreamIFCRef | convertToFiniteStream () |
void | prepareForRetry () |
void | handleAuth () |
void | checkConnection () |
String | checkResponse (Resp_t &rt) |
void | prepareHeaders () |
void | sendDataToServer (const Reference< TempFileStream > &tfs, const String &methodName, const String &cimObject, ERequestType requestType) |
void | getCredentialsIfNecessary () |
If no credentials were provided in the url to the constructor, but an authentication callback was given, then call the callback to get credentials. | |
void | copyStreams (std::ostream &ostr, std::istream &istr) |
void | getStatusLine () |
sets m_statusLine if there is a status line to be read, this function doesn't block. | |
EStatusLineSummary | checkAndExamineStatusLine () |
HTTPClient (const HTTPClient &) | |
HTTPClient & | operator= (const HTTPClient &) |
Private Attributes | |
String | m_sAuthorization |
String | m_sRealm |
String | m_sDigestNonce |
String | m_sDigestCNonce |
UInt8 | m_iDigestNonceCount |
String | m_sDigestSessionKey |
String | m_sDigestResponse |
SocketAddress | m_serverAddress |
URL | m_url |
HTTPHeaderMap | m_responseHeaders |
Array< String > | m_requestHeadersPersistent |
Array< String > | m_requestHeadersCommon |
Array< String > | m_requestHeadersNew |
CIMProtocolIStreamIFCRef | m_pIstrReturn |
SSLClientCtxRef | m_sslCtx |
Socket | m_socket |
String | m_requestMethod |
bool | m_authRequired |
std::istream & | m_istr |
std::ostream & | m_ostr |
bool | m_doDeflateOut |
int | m_retryCount |
String | m_httpPath |
bool | m_uselocalAuthentication |
String | m_localNonce |
String | m_localCookieFile |
String | m_statusLine |
It handles the details of the HTTP protocol.
By default the connection timeout is set to 1 minute, and the send and receive timeouts are set to 10 minutes.
Thread safety: non-reentrant. Copy semantics: Non-copyable. Exception safety: Basic.
Definition at line 66 of file OW_HTTPClient.hpp.
|
if the server has disconnected or sent us something since our last request (remember connections are persistent), we need to process it *before* we send another request, or if we get something while we are sending, we need to look at the header to know if we should keep sending data. This function doesn't block, it just looks to see if there is a http status line on the incoming socket, and if so it reads it and examines the status code. If there is no input or If the status code < 300, E_STATUS_GOOD is returned, else E_STATUS_ERROR. Definition at line 341 of file OW_HTTPClient.hpp. |
|
Definition at line 243 of file OW_HTTPClient.hpp. |
|
Creates an httpClient object. This represents one client connection to a CIMOM.
A port may be a number to indicate a TCP port, or it may be the special value owipc which indicates the Unix Domain Socket for the system. example: "https://jdd:test@myhost.com:5989/root/cimv2" If (principal == "" && (host == "localhost" || host == "127.0.0.1")) then HTTPClient will attempt to use OWLocal authentication.
Definition at line 65 of file OW_HTTPClient.cpp. |
|
Definition at line 116 of file OW_HTTPClient.cpp. References cleanUpIStreams(). |
|
|
|
Add a custom header to add to requests. "<name>: <value>" will be added to each request.
Definition at line 353 of file OW_HTTPClient.cpp. References addHeaderPersistent(), and name. |
|
Definition at line 290 of file OW_HTTPClient.hpp. References OW_NAMESPACE::HTTPUtils::addHeader(). |
|
Definition at line 298 of file OW_HTTPClient.hpp. References OW_NAMESPACE::HTTPUtils::addHeader(). Referenced by sendDataToServer(). |
|
Definition at line 294 of file OW_HTTPClient.hpp. References OW_NAMESPACE::HTTPUtils::addHeader(). Referenced by addCustomHeader(). |
|
After calling this function, the next request will (re)connect and send credentials using basic authentication. This could be a security risk, and should only be used if you understand the risks. Using this avoids the extra round-trip that typically happens with http authentication. Definition at line 1059 of file OW_HTTPClient.cpp. References close(), m_authRequired, m_sAuthorization, and m_uselocalAuthentication. |
|
Implements OW_NAMESPACE::CIMProtocolIFC. Definition at line 593 of file OW_HTTPClient.cpp. |
|
Definition at line 431 of file OW_HTTPClient.cpp. References E_STATUS_ERROR, getStatusLine(), OW_NAMESPACE::Socket::isConnected(), m_socket, m_statusLine, OW_NAMESPACE::String::tokenize(), and OW_NAMESPACE::Socket::waitForInput(). Referenced by copyStreams(). |
|
Definition at line 958 of file OW_HTTPClient.cpp. References OW_NAMESPACE::Socket::connect(), OW_NAMESPACE::Socket::disconnect(), OW_NAMESPACE::Socket::isConnected(), m_istr, m_ostr, m_serverAddress, and m_socket. Referenced by getFeatures(), and sendDataToServer(). |
|
Definition at line 978 of file OW_HTTPClient.cpp. References close(), CONTINUE, FATAL, OW_NAMESPACE::Socket::getReceiveTimeout(), getStatusLine(), m_istr, m_responseHeaders, m_socket, m_statusLine, OW_THROW, OW_NAMESPACE::HTTPUtils::parseHeader(), prepareForRetry(), processHeaders(), and OW_NAMESPACE::Socket::receiveTimeOutExpired(). Referenced by getFeatures(). |
|
Definition at line 129 of file OW_HTTPClient.cpp. References OW_NAMESPACE::HTTPUtils::eatEntity(), and m_pIstrReturn. Referenced by ~HTTPClient(). |
|
Close the connetion to the CIMOM. This will free resources used for the client session. Implements OW_NAMESPACE::CIMProtocolIFC. Definition at line 1068 of file OW_HTTPClient.cpp. References OW_NAMESPACE::Socket::disconnect(), and m_socket. Referenced by assumeBasicAuth(), checkResponse(), and processHeaders(). |
|
Definition at line 922 of file OW_HTTPClient.cpp. References getHeaderValue(), headerHasKey(), OW_NAMESPACE::HTTPChunkedIStream, m_istr, OW_THROW, and OW_NAMESPACE::String::toUInt64(). Referenced by prepareForRetry(). |
|
Definition at line 465 of file OW_HTTPClient.cpp. References checkAndExamineStatusLine(), and E_STATUS_ERROR. |
|
Establishes a connection (if not already connected) to the CIMOM and sends a request. An istream& is returned containing the response from the CIMOM, after protocol processing is done.
Definition at line 600 of file OW_HTTPClient.cpp. References OW_NAMESPACE::Reference< T >::cast_to(), OW_ASSERT, and OW_THROW. |
|
Get the connect timeout.
Implements OW_NAMESPACE::CIMProtocolIFC. Definition at line 1111 of file OW_HTTPClient.cpp. References OW_NAMESPACE::Socket::getConnectTimeout(), and m_socket. |
|
If no credentials were provided in the url to the constructor, but an authentication callback was given, then call the callback to get credentials. m_url.principal != ""
Definition at line 318 of file OW_HTTPClient.cpp. References OW_NAMESPACE::URL::credential, OW_NAMESPACE::String::empty(), OW_NAMESPACE::CIMProtocolIFC::m_loginCB, m_sRealm, m_url, name, OW_THROW, OW_NAMESPACE::URL::principal, and OW_NAMESPACE::URL::toString(). Referenced by sendAuthorization(). |
|
Sends an OPTIONS request to the HTTP server, and reports the results.
Implements OW_NAMESPACE::CIMProtocolIFC. Definition at line 668 of file OW_HTTPClient.cpp. References checkConnection(), checkResponse(), OW_NAMESPACE::Map< Key, T, Compare >::clear(), OW_NAMESPACE::Array< T >::clear(), OW_NAMESPACE::String::erase(), OW_NAMESPACE::CIMFeatures::extURL, FATAL, getHeaderValue(), handleAuth(), OW_NAMESPACE::String::indexOf(), OW_NAMESPACE::String::length(), m_doDeflateOut, m_ostr, m_requestHeadersNew, m_requestMethod, m_responseHeaders, m_statusLine, OW_NAMESPACE::String::npos, OW_THROW, prepareHeaders(), RETRY, sendHeaders(), OW_NAMESPACE::String::substring(), and OW_NAMESPACE::String::trim(). |
|
Definition at line 286 of file OW_HTTPClient.hpp. References OW_NAMESPACE::HTTPUtils::getHeaderValue(). Referenced by convertToFiniteStream(), getFeatures(), processHeaders(), and receiveAuthentication(). |
|
Gets the address of the local machine.
Implements OW_NAMESPACE::CIMProtocolIFC. Definition at line 1032 of file OW_HTTPClient.cpp. References OW_NAMESPACE::Socket::connect(), OW_NAMESPACE::Socket::isConnected(), m_serverAddress, and m_socket. |
|
Gets the address of the peer connection.
Implements OW_NAMESPACE::CIMProtocolIFC. Definition at line 1042 of file OW_HTTPClient.cpp. References OW_NAMESPACE::Socket::connect(), OW_NAMESPACE::Socket::isConnected(), m_serverAddress, and m_socket. |
|
Get the receive timeout.
Implements OW_NAMESPACE::CIMProtocolIFC. Definition at line 1083 of file OW_HTTPClient.cpp. References OW_NAMESPACE::Socket::getReceiveTimeout(), and m_socket. |
|
Retrieve a given header value from the server response.
Definition at line 359 of file OW_HTTPClient.cpp. References OW_NAMESPACE::HTTPUtils::getHeaderValue(), OW_NAMESPACE::HTTPUtils::headerHasKey(), and m_responseHeaders. |
|
Get the send timeout.
Implements OW_NAMESPACE::CIMProtocolIFC. Definition at line 1097 of file OW_HTTPClient.cpp. References OW_NAMESPACE::Socket::getSendTimeout(), and m_socket. |
|
sets m_statusLine if there is a status line to be read, this function doesn't block.
Definition at line 968 of file OW_HTTPClient.cpp. References OW_NAMESPACE::String::empty(), OW_NAMESPACE::String::getLine(), m_istr, m_statusLine, and OW_NAMESPACE::String::trim(). Referenced by checkAndExamineStatusLine(), and checkResponse(). |
|
Definition at line 947 of file OW_HTTPClient.cpp. References m_authRequired, m_uselocalAuthentication, receiveAuthentication(), and sendAuthorization(). Referenced by getFeatures(), and sendDataToServer(). |
|
Definition at line 282 of file OW_HTTPClient.hpp. References OW_NAMESPACE::HTTPUtils::headerHasKey(). Referenced by convertToFiniteStream(). |
|
|
|
Definition at line 762 of file OW_HTTPClient.cpp. References convertToFiniteStream(), and OW_NAMESPACE::HTTPUtils::eatEntity(). Referenced by checkResponse(). |
|
Definition at line 1025 of file OW_HTTPClient.cpp. References OW_NAMESPACE::Map< Key, T, Compare >::clear(), OW_NAMESPACE::Array< T >::clear(), m_requestHeadersCommon, and m_responseHeaders. Referenced by getFeatures(). |
|
precondition: m_statusLine is set to the status line, and the headers have been read
Definition at line 792 of file OW_HTTPClient.cpp. References close(), getHeaderValue(), OW_NAMESPACE::String::indexOf(), OW_NAMESPACE::String::length(), m_statusLine, OW_NAMESPACE::String::npos, RETRY, OW_NAMESPACE::String::substring(), and OW_NAMESPACE::String::toInt32(). Referenced by checkResponse(). |
|
Definition at line 252 of file OW_HTTPClient.cpp. References OW_NAMESPACE::String::empty(), getHeaderValue(), OW_NAMESPACE::String::tokenize(), and OW_NAMESPACE::String::toLowerCase(). Referenced by handleAuth(). |
|
|
|
|
Definition at line 503 of file OW_HTTPClient.cpp. References addHeaderNew(), checkConnection(), OW_NAMESPACE::String::equals(), OW_NAMESPACE::HTTPUtils::getCounterStr(), handleAuth(), and m_requestMethod. |
|
Definition at line 772 of file OW_HTTPClient.cpp. References i, m_httpPath, m_ostr, m_requestHeadersPersistent, and OW_NAMESPACE::Array< T >::size(). Referenced by getFeatures(). |
|
Set the connect timeout on the socket.
Implements OW_NAMESPACE::CIMProtocolIFC. Definition at line 1104 of file OW_HTTPClient.cpp. References m_socket, and OW_NAMESPACE::Socket::setConnectTimeout(). |
|
Set the HTTP path to use. Previously this was specified in the URL, however now with the WBEM URI spec, that portion of the URL is allocated to the namespace name. To use a different HTTP path (the path the M-POST is sent to), call this function. An initial / will not be prepended. The default HTTP path is "/cimom"
Definition at line 1053 of file OW_HTTPClient.cpp. References m_httpPath. |
|
Set the receive timeout on the socket.
Implements OW_NAMESPACE::CIMProtocolIFC. Definition at line 1076 of file OW_HTTPClient.cpp. References m_socket, and OW_NAMESPACE::Socket::setReceiveTimeout(). |
|
Set the send timeout on the socket.
Implements OW_NAMESPACE::CIMProtocolIFC. Definition at line 1090 of file OW_HTTPClient.cpp. References m_socket, and OW_NAMESPACE::Socket::setSendTimeout(). |
|
Set all timeouts (send, receive, connect).
Implements OW_NAMESPACE::CIMProtocolIFC. Definition at line 1118 of file OW_HTTPClient.cpp. References m_socket, and OW_NAMESPACE::Socket::setTimeouts(). |
|
Definition at line 199 of file OW_HTTPClient.cpp. References OW_NAMESPACE::String::empty(), m_url, and OW_NAMESPACE::URL::scheme. |
|
Reimplemented from OW_NAMESPACE::CIMProtocolIFC. Definition at line 180 of file OW_HTTPClient.hpp. |
|
Definition at line 267 of file OW_HTTPClient.hpp. Referenced by assumeBasicAuth(), and handleAuth(). |
|
Definition at line 270 of file OW_HTTPClient.hpp. Referenced by getFeatures(). |
|
Definition at line 272 of file OW_HTTPClient.hpp. Referenced by sendAuthorization(), sendHeaders(), and setHTTPPath(). |
|
Definition at line 239 of file OW_HTTPClient.hpp. Referenced by sendAuthorization(). |
|
Definition at line 268 of file OW_HTTPClient.hpp. Referenced by checkConnection(), checkResponse(), convertToFiniteStream(), and getStatusLine(). |
|
Definition at line 275 of file OW_HTTPClient.hpp. Referenced by sendAuthorization(). |
|
Definition at line 274 of file OW_HTTPClient.hpp. Referenced by sendAuthorization(). |
|
Definition at line 269 of file OW_HTTPClient.hpp. Referenced by checkConnection(), getFeatures(), and sendHeaders(). |
|
Definition at line 263 of file OW_HTTPClient.hpp. Referenced by cleanUpIStreams(). |
|
Definition at line 259 of file OW_HTTPClient.hpp. Referenced by prepareHeaders(). |
|
Definition at line 262 of file OW_HTTPClient.hpp. Referenced by getFeatures(). |
|
Definition at line 255 of file OW_HTTPClient.hpp. Referenced by sendHeaders(). |
|
Definition at line 266 of file OW_HTTPClient.hpp. Referenced by getFeatures(), sendAuthorization(), and sendDataToServer(). |
|
Definition at line 252 of file OW_HTTPClient.hpp. Referenced by checkResponse(), getFeatures(), getResponseHeader(), and prepareHeaders(). |
|
Definition at line 271 of file OW_HTTPClient.hpp. |
|
Definition at line 233 of file OW_HTTPClient.hpp. Referenced by assumeBasicAuth(), and sendAuthorization(). |
|
Definition at line 238 of file OW_HTTPClient.hpp. Referenced by sendAuthorization(). |
|
Definition at line 237 of file OW_HTTPClient.hpp. Referenced by sendAuthorization(). |
|
Definition at line 241 of file OW_HTTPClient.hpp. Referenced by sendAuthorization(). |
|
Definition at line 240 of file OW_HTTPClient.hpp. Referenced by sendAuthorization(). |
|
Definition at line 250 of file OW_HTTPClient.hpp. Referenced by checkConnection(), getLocalAddress(), and getPeerAddress(). |
|
Definition at line 265 of file OW_HTTPClient.hpp. Referenced by checkAndExamineStatusLine(), checkConnection(), checkResponse(), close(), getConnectTimeout(), getLocalAddress(), getPeerAddress(), getReceiveTimeout(), getSendTimeout(), setConnectTimeout(), setReceiveTimeout(), setSendTimeout(), and setTimeouts(). |
|
Definition at line 234 of file OW_HTTPClient.hpp. Referenced by getCredentialsIfNecessary(), and sendAuthorization(). |
|
Definition at line 264 of file OW_HTTPClient.hpp. |
|
Definition at line 276 of file OW_HTTPClient.hpp. Referenced by checkAndExamineStatusLine(), checkResponse(), getFeatures(), getStatusLine(), and processHeaders(). |
|
Definition at line 251 of file OW_HTTPClient.hpp. Referenced by getCredentialsIfNecessary(), sendAuthorization(), and setUrl(). |
|
Definition at line 273 of file OW_HTTPClient.hpp. Referenced by assumeBasicAuth(), and handleAuth(). |