![]() |
libhomegear-base
0.7
Base library for Homegear and Homegear family modules.
|
This class provides a basic HTTP client. More...
#include <HttpClient.h>
Public Member Functions | |
| HttpClient (BaseLib::SharedObjects *baseLib, std::string hostname, int32_t port=80, bool keepAlive=true, bool useSSL=false, std::string caFile="", bool verifyCertificate=true, std::string certPath="", std::string keyPath="") | |
| Constructor. More... | |
| HttpClient (BaseLib::SharedObjects *baseLib, std::string hostname, int32_t port, bool keepAlive, bool useSSL, bool verifyCertificate, std::string caFile, std::string caData, std::string certPath, std::string certData, std::string keyPath, const std::shared_ptr< Security::SecureVector< uint8_t >> &keyData) | |
| Constructor. More... | |
| virtual | ~HttpClient () |
| Destructor. More... | |
| std::shared_ptr< TcpSocket > | getSocket () |
| Returns the underlying TcpSocket. More... | |
| void | setTimeout (uint32_t value) |
| Sets the socket timeout. More... | |
| void | setVerifyHostname (bool value) |
| void | setUserAgent (const std::string &value) |
| By default the header "User-Agent" is set to "Homegear". More... | |
| bool | connected () |
| Returns "true" if the socket is connected, otherwise "false". More... | |
| void | disconnect () |
| Closes the socket. More... | |
| void | enableRawContent (bool value) |
| Enables storage of raw content. More... | |
| std::vector< char > & | getRawContent () |
| Returns the raw content. More... | |
| std::string | getIpAddress () |
| Returns the IP address of the HTTP server. More... | |
| void | sendRequest (const std::string &request, std::string &response, bool responseIsHeaderOnly=false) |
| void | sendRequest (const std::string &request, Http &response, bool responseIsHeaderOnly=false) |
| void | delete_ (const std::string &path, std::string &data, const std::string &additionalHeaders="") |
| void | delete_ (const std::string &path, Http &data, const std::string &additionalHeaders="") |
| void | get (const std::string &path, std::string &data, const std::string &additionalHeaders="") |
| void | get (const std::string &path, Http &data, const std::string &additionalHeaders="") |
| void | patch (const std::string &path, std::string &dataIn, std::string &dataOut, const std::string &additionalHeaders="") |
| void | patch (const std::string &path, std::string &dataIn, Http &dataOut, const std::string &additionalHeaders="") |
| void | post (const std::string &path, std::string &dataIn, std::string &dataOut, const std::string &additionalHeaders="") |
| void | post (const std::string &path, std::string &dataIn, Http &dataOut, const std::string &additionalHeaders="") |
| void | put (const std::string &path, std::string &dataIn, std::string &dataOut, const std::string &additionalHeaders="") |
| void | put (const std::string &path, std::string &dataIn, Http &dataOut, const std::string &additionalHeaders="") |
Protected Attributes | |
| BaseLib::SharedObjects * | _bl = nullptr |
| The common base library object. More... | |
| std::mutex | _socketMutex |
| Protects _socket to only allow one operation at a time. More... | |
| std::shared_ptr< TcpSocket > | _socket |
| The socket object. More... | |
| std::string | _hostname = "" |
| The hostname of the HTTP server. More... | |
| int32_t | _port = 80 |
| The port the HTTP server listens on. More... | |
| bool | _keepAlive = true |
| Stores the information if the socket connection should be kept open after each request. More... | |
| bool | _keepRawContent = false |
| When true, the raw content is stored. More... | |
| std::string | _userAgent = "Homegear" |
| std::vector< char > | _rawContent |
| Stores the raw response. More... | |
This class provides a basic HTTP client.
The class is thread safe.
| BaseLib::HttpClient::HttpClient | ( | BaseLib::SharedObjects * | baseLib, |
| std::string | hostname, | ||
| int32_t | port = 80, |
||
| bool | keepAlive = true, |
||
| bool | useSSL = false, |
||
| std::string | caFile = "", |
||
| bool | verifyCertificate = true, |
||
| std::string | certPath = "", |
||
| std::string | keyPath = "" |
||
| ) |
Constructor.
| baseLib | The common base library object. |
| hostname | The hostname of the client to connect to without "http://". |
| port | (default 80) The port to connect to. |
| keepAlive | (default true) Keep the socket open after each request. |
| useSSL | (default false) Set to "true" to use "https". |
| caFile | (default "") Path to the certificate authority file of the certificate authority which signed the server certificate. |
| verifyCertificate | (default true) Set to "true" to verify the server certificate (highly recommended). |
| certPath | (default "") Path to the PEM encoded client certificate |
| keyPath | (default "") Path to the PEM encoded client keyfile |
| BaseLib::HttpClient::HttpClient | ( | BaseLib::SharedObjects * | baseLib, |
| std::string | hostname, | ||
| int32_t | port, | ||
| bool | keepAlive, | ||
| bool | useSSL, | ||
| bool | verifyCertificate, | ||
| std::string | caFile, | ||
| std::string | caData, | ||
| std::string | certPath, | ||
| std::string | certData, | ||
| std::string | keyPath, | ||
| const std::shared_ptr< Security::SecureVector< uint8_t >> & | keyData | ||
| ) |
Constructor.
...Data or ...File are chosen automatically. Just leave the one you don't want to use empty.
| baseLib | The common base library object. |
| hostname | The hostname of the client to connect to without "http://". |
| port | (default 80) The port to connect to. |
| keepAlive | (default true) Keep the socket open after each request. |
| useSSL | (default false) Set to "true" to use "https". |
| verifyCertificate | (default true) Set to "true" to verify the server certificate (highly recommended). |
| caFile | (default "") Path to the certificate authority file of the certificate authority which signed the server certificate. |
| caData | The PEM-encoded CA certificate (not the path) used to sign the server certificate. |
| certPath | (default "") Path to the PEM encoded client certificate |
| clientCertData | The PEM-encoded client certificate (not the path). |
| keyPath | (default "") Path to the PEM encoded client keyfile |
| keyData | The PEM-encoded client key (not the path). |
|
virtual |
Destructor.
|
inline |
Returns "true" if the socket is connected, otherwise "false".
| void BaseLib::HttpClient::delete_ | ( | const std::string & | path, |
| std::string & | data, | ||
| const std::string & | additionalHeaders = "" |
||
| ) |
| void BaseLib::HttpClient::delete_ | ( | const std::string & | path, |
| Http & | data, | ||
| const std::string & | additionalHeaders = "" |
||
| ) |
|
inline |
Closes the socket.
|
inline |
Enables storage of raw content.
The raw content can be retrieved with getRawContent().
| value | Set to true to enable. |
| void BaseLib::HttpClient::get | ( | const std::string & | path, |
| std::string & | data, | ||
| const std::string & | additionalHeaders = "" |
||
| ) |
| void BaseLib::HttpClient::get | ( | const std::string & | path, |
| Http & | data, | ||
| const std::string & | additionalHeaders = "" |
||
| ) |
|
inline |
Returns the IP address of the HTTP server.
|
inline |
Returns the raw content.
Only available when enableRawContent() was set to true.
|
inline |
| void BaseLib::HttpClient::patch | ( | const std::string & | path, |
| std::string & | dataIn, | ||
| std::string & | dataOut, | ||
| const std::string & | additionalHeaders = "" |
||
| ) |
| void BaseLib::HttpClient::patch | ( | const std::string & | path, |
| std::string & | dataIn, | ||
| Http & | dataOut, | ||
| const std::string & | additionalHeaders = "" |
||
| ) |
| void BaseLib::HttpClient::post | ( | const std::string & | path, |
| std::string & | dataIn, | ||
| std::string & | dataOut, | ||
| const std::string & | additionalHeaders = "" |
||
| ) |
| void BaseLib::HttpClient::post | ( | const std::string & | path, |
| std::string & | dataIn, | ||
| Http & | dataOut, | ||
| const std::string & | additionalHeaders = "" |
||
| ) |
| void BaseLib::HttpClient::put | ( | const std::string & | path, |
| std::string & | dataIn, | ||
| std::string & | dataOut, | ||
| const std::string & | additionalHeaders = "" |
||
| ) |
| void BaseLib::HttpClient::put | ( | const std::string & | path, |
| std::string & | dataIn, | ||
| Http & | dataOut, | ||
| const std::string & | additionalHeaders = "" |
||
| ) |
| void BaseLib::HttpClient::sendRequest | ( | const std::string & | request, |
| std::string & | response, | ||
| bool | responseIsHeaderOnly = false |
||
| ) |
| void BaseLib::HttpClient::sendRequest | ( | const std::string & | request, |
| Http & | response, | ||
| bool | responseIsHeaderOnly = false |
||
| ) |
| void BaseLib::HttpClient::setTimeout | ( | uint32_t | value | ) |
Sets the socket timeout.
| value | The timeout in milliseconds. |
| void BaseLib::HttpClient::setUserAgent | ( | const std::string & | value | ) |
By default the header "User-Agent" is set to "Homegear".
To change the user agent string, call this method.
| value | The new user agent. |
| void BaseLib::HttpClient::setVerifyHostname | ( | bool | value | ) |
|
protected |
The common base library object.
|
protected |
The hostname of the HTTP server.
|
protected |
Stores the information if the socket connection should be kept open after each request.
|
protected |
When true, the raw content is stored.
|
protected |
The port the HTTP server listens on.
|
protected |
Stores the raw response.
|
protected |
The socket object.
|
protected |
Protects _socket to only allow one operation at a time.
|
protected |