|
ndmspc v1.2.0-0.1.rc7
|
Provides HTTP request functionality using libcurl. More...
#include <NHttpRequest.h>
Public Member Functions | |
| NHttpRequest () | |
| Constructs a new NHttpRequest instance. | |
| virtual | ~NHttpRequest () |
| Destroys the NHttpRequest instance. | |
| std::string | get (const std::string &url, const std::string &cert_path="", const std::string &key_path="", const std::string &key_password_file="", bool insecure=false) |
| Performs an HTTP GET request. | |
| std::string | post (const std::string &url, const std::string &post_data, const std::string &cert_path="", const std::string &key_path="", const std::string &key_password_file="", bool insecure=false) |
| Performs an HTTP POST request. | |
| int | head (const std::string &url, const std::string &cert_path="", const std::string &key_path="", const std::string &key_password_file="", bool insecure=false) |
| Performs an HTTP HEAD request. | |
Private Member Functions | |
| CURLcode | request (const std::string &method, const std::string &url, const std::string &data, std::ostringstream &response, const std::string &cert_path, const std::string &key_path, const std::string &key_password_file, bool insecure) |
| Internal method to perform an HTTP request. | |
| void | throw_curl_error (CURLcode res) const |
| Throws an exception if a CURL error occurs. | |
Static Private Member Functions | |
| static size_t | WriteCallback (void *contents, size_t size, size_t nmemb, void *userp) |
| Callback for writing response data. | |
| static size_t | HeaderCallback (char *buffer, size_t size, size_t nitems, void *userdata) |
| Callback for handling response headers. | |
Private Attributes | |
| CURL * | curl |
| libcurl handle | |
| struct curl_slist * | headers |
| List of custom headers. | |
| std::vector< std::string > | received_headers |
| Received response headers. | |
Provides HTTP request functionality using libcurl.
NHttpRequest wraps libcurl to perform HTTP GET, POST, and HEAD requests, supporting client certificate authentication and custom error handling. It offers methods for sending requests and retrieving responses, and handles headers and SSL options.
Definition at line 21 of file NHttpRequest.h.
| Ndmspc::NHttpRequest::NHttpRequest | ( | ) |
Constructs a new NHttpRequest instance.
Definition at line 12 of file NHttpRequest.cxx.
|
virtual |
Destroys the NHttpRequest instance.
Definition at line 21 of file NHttpRequest.cxx.
| std::string Ndmspc::NHttpRequest::get | ( | const std::string & | url, |
| const std::string & | cert_path = "", | ||
| const std::string & | key_path = "", | ||
| const std::string & | key_password_file = "", | ||
| bool | insecure = false ) |
Performs an HTTP GET request.
| url | The target URL. |
| cert_path | Path to client certificate (optional). |
| key_path | Path to private key (optional). |
| key_password_file | Path to key password file (optional). |
| insecure | If true, disables SSL verification. |
Definition at line 32 of file NHttpRequest.cxx.
References request(), and throw_curl_error().
Referenced by Ndmspc::NUtils::OpenMacro().
| int Ndmspc::NHttpRequest::head | ( | const std::string & | url, |
| const std::string & | cert_path = "", | ||
| const std::string & | key_path = "", | ||
| const std::string & | key_password_file = "", | ||
| bool | insecure = false ) |
Performs an HTTP HEAD request.
| url | The target URL. |
| cert_path | Path to client certificate (optional). |
| key_path | Path to private key (optional). |
| key_password_file | Path to key password file (optional). |
| insecure | If true, disables SSL verification. |
Definition at line 56 of file NHttpRequest.cxx.
References received_headers, request(), and throw_curl_error().
Referenced by Ndmspc::NUtils::AccessPathName().
|
staticprivate |
Callback for handling response headers.
| buffer | Pointer to header data. |
| size | Size of a data unit. |
| nitems | Number of data units. |
| userdata | User pointer (header storage). |
Definition at line 186 of file NHttpRequest.cxx.
References headers.
Referenced by request().
| std::string Ndmspc::NHttpRequest::post | ( | const std::string & | url, |
| const std::string & | post_data, | ||
| const std::string & | cert_path = "", | ||
| const std::string & | key_path = "", | ||
| const std::string & | key_password_file = "", | ||
| bool | insecure = false ) |
Performs an HTTP POST request.
| url | The target URL. |
| post_data | Data to post. |
| cert_path | Path to client certificate (optional). |
| key_path | Path to private key (optional). |
| key_password_file | Path to key password file (optional). |
| insecure | If true, disables SSL verification. |
Definition at line 44 of file NHttpRequest.cxx.
References request(), and throw_curl_error().
|
private |
Internal method to perform an HTTP request.
| method | HTTP method ("GET", "POST", "HEAD"). |
| url | The target URL. |
| data | Data to send (for POST). |
| response | Output stream for response data. |
| cert_path | Path to client certificate. |
| key_path | Path to private key. |
| key_password_file | Path to key password file. |
| insecure | If true, disables SSL verification. |
Definition at line 76 of file NHttpRequest.cxx.
References curl, HeaderCallback(), headers, received_headers, and WriteCallback().
|
private |
Throws an exception if a CURL error occurs.
| res | CURLcode result. |
Definition at line 208 of file NHttpRequest.cxx.
|
staticprivate |
Callback for writing response data.
| contents | Pointer to received data. |
| size | Size of a data unit. |
| nmemb | Number of data units. |
| userp | User pointer (output stream). |
Definition at line 180 of file NHttpRequest.cxx.
Referenced by request().
|
private |
libcurl handle
Definition at line 108 of file NHttpRequest.h.
Referenced by NHttpRequest(), request(), and ~NHttpRequest().
|
private |
List of custom headers.
Definition at line 109 of file NHttpRequest.h.
Referenced by HeaderCallback(), NHttpRequest(), request(), and ~NHttpRequest().
|
private |
Received response headers.
Definition at line 110 of file NHttpRequest.h.