repeat HTTP requests once
This commit is contained in:
@@ -431,12 +431,12 @@ void HttpClient::disconnect() {
|
||||
}
|
||||
}
|
||||
|
||||
bool HttpClient::get(const string& uri, const string& body, string* response, time_t* time) {
|
||||
return request("GET", uri, body, response, time);
|
||||
bool HttpClient::get(const string& uri, const string& body, string* response, bool* repeatable, time_t* time) {
|
||||
return request("GET", uri, body, response, repeatable, time);
|
||||
}
|
||||
|
||||
bool HttpClient::post(const string& uri, const string& body, string* response) {
|
||||
return request("POST", uri, body, response);
|
||||
bool HttpClient::post(const string& uri, const string& body, string* response, bool* repeatable) {
|
||||
return request("POST", uri, body, response, repeatable);
|
||||
}
|
||||
|
||||
const int indexToMonth[] = {
|
||||
@@ -446,9 +446,13 @@ const int indexToMonth[] = {
|
||||
-1, -1, 4, -1, -1, -1, -1, -1, // 24-31
|
||||
};
|
||||
|
||||
bool HttpClient::request(const string& method, const string& uri, const string& body, string* response, time_t* time) {
|
||||
bool HttpClient::request(const string& method, const string& uri, const string& body, string* response,
|
||||
bool* repeatable, time_t* time) {
|
||||
if (!ensureConnected()) {
|
||||
*response = "not connected";
|
||||
if (repeatable) {
|
||||
*repeatable = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
ostringstream ostr;
|
||||
@@ -473,6 +477,9 @@ bool HttpClient::request(const string& method, const string& uri, const string&
|
||||
if (sent < 0) {
|
||||
disconnect();
|
||||
*response = "send error";
|
||||
if (repeatable) {
|
||||
*repeatable = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
pos += sent;
|
||||
|
||||
@@ -188,19 +188,24 @@ class HttpClient {
|
||||
* @param uri the URI string.
|
||||
* @param body the optional body to send.
|
||||
* @param response the response body from the server (or the HTTP header on error).
|
||||
* @param repeatable optional pointer to a bool in which to store whether the request should be repeated later on
|
||||
* (e.g. due to temporary connectivity issues).
|
||||
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or nullptr.
|
||||
* @return true on success, false on error.
|
||||
*/
|
||||
bool get(const string& uri, const string& body, string* response, time_t* time = nullptr);
|
||||
bool get(const string& uri, const string& body, string* response, bool* repeatable = nullptr,
|
||||
time_t* time = nullptr);
|
||||
|
||||
/**
|
||||
* Execute a POST request.
|
||||
* @param uri the URI string.
|
||||
* @param body the optional body to send.
|
||||
* @param response the response body from the server (or the HTTP header on error).
|
||||
* @param repeatable optional pointer to a bool in which to store whether the request should be repeated later on
|
||||
* (e.g. due to temporary connectivity issues).
|
||||
* @return true on success, false on error.
|
||||
*/
|
||||
bool post(const string& uri, const string& body, string* response);
|
||||
bool post(const string& uri, const string& body, string* response, bool* repeatable = nullptr);
|
||||
|
||||
/**
|
||||
* Execute an arbitrary request.
|
||||
@@ -208,10 +213,13 @@ class HttpClient {
|
||||
* @param uri the URI string.
|
||||
* @param body the optional body to send.
|
||||
* @param response the response body from the server (or the HTTP header on error).
|
||||
* @param repeatable optional pointer to a bool in which to store whether the request should be repeated later on
|
||||
* (e.g. due to temporary connectivity issues).
|
||||
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or nullptr.
|
||||
* @return true on success, false on error.
|
||||
*/
|
||||
bool request(const string& method, const string& uri, const string& body, string* response, time_t* time = nullptr);
|
||||
bool request(const string& method, const string& uri, const string& body, string* response,
|
||||
bool* repeatable = nullptr, time_t* time = nullptr);
|
||||
|
||||
private:
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user