![]() |
OpenMS
|
Synchronous HTTP GET request backed by libcurl. More...
#include <OpenMS/SYSTEM/NetworkGetRequest.h>
Public Member Functions | |
| NetworkGetRequest () | |
| ~NetworkGetRequest () | |
| void | setUrl (const std::string &url) |
| Set the URL to request. | |
| void | setTimeout (int seconds) |
| Set the request timeout in seconds. | |
| void | run () |
| Execute the GET request synchronously. | |
| std::string | getResponse () const |
| Response body as a string. | |
| const std::vector< char > & | getResponseBinary () const |
| Raw response body. | |
| bool | hasError () const |
| Whether the last run produced an error. | |
| std::string | getErrorString () const |
| Human-readable description of the last error. | |
Private Member Functions | |
| NetworkGetRequest (const NetworkGetRequest &)=delete | |
| NetworkGetRequest & | operator= (const NetworkGetRequest &)=delete |
Private Attributes | |
| std::vector< char > | response_bytes_ |
| std::string | url_ |
| int | timeout_ = 0 |
| bool | has_error_ = false |
| std::string | error_string_ |
Synchronous HTTP GET request backed by libcurl.
Typical lifecycle: set the URL via setUrl, optionally set a timeout via setTimeout, call run to perform the request, then read the result via getResponse / getResponseBinary or check hasError / getErrorString. The instance can be reused for further requests; each call to run replaces the previously observed state. Redirects are followed automatically.
Failures (libcurl initialisation, transport errors, HTTP status >= 400) are reported through hasError and getErrorString; run does not throw on those conditions.
Instances are not copyable.
| ~NetworkGetRequest | ( | ) |
|
privatedelete |
| std::string getErrorString | ( | ) | const |
Human-readable description of the last error.
false. | std::string getResponse | ( | ) | const |
Response body as a string.
std::string. | const std::vector< char > & getResponseBinary | ( | ) | const |
Raw response body.
| bool hasError | ( | ) | const |
|
privatedelete |
| void run | ( | ) |
Execute the GET request synchronously.
Performs the request configured by the last setUrl / setTimeout call, blocking the caller until the response is complete or libcurl reports a timeout / error. Redirects are followed. The previous response and error state are cleared at the start of the call.
The call sets hasError to true when:
"Failed to initialize libcurl"),curl_easy_strerror), or>= 400 (error string "HTTP error N", where N is the status code).No exception is thrown for any of these.
| void setTimeout | ( | int | seconds | ) |
Set the request timeout in seconds.
| [in] | seconds | Timeout in seconds. 0 (the default) leaves the timeout unset, so the request blocks until the server responds or libcurl gives up on its own. |
| void setUrl | ( | const std::string & | url | ) |
|
private |
|
private |
|
private |
|
private |
|
private |