Support Retry-After.

GitOrigin-RevId: ca7cf22cf166aa75bb9266faa3b5d04df3c2ec5b
This commit is contained in:
levlam 2018-04-19 15:03:10 +03:00
parent 0c785aa361
commit 05d17c3396
2 changed files with 17 additions and 0 deletions

View File

@ -6,6 +6,8 @@
//
#include "td/net/HttpQuery.h"
#include "td/utils/misc.h"
#include <algorithm>
namespace td {
@ -30,6 +32,19 @@ std::vector<std::pair<string, string>> HttpQuery::string_args() const {
return res;
}
int HttpQuery::get_retry_after() const {
auto value = header("retry-after");
if (value.empty()) {
return 0;
}
auto r_retry_after = to_integer_safe<int>(value);
if (r_retry_after.is_error()) {
return 0;
}
return td::max(0, r_retry_after.ok());
}
StringBuilder &operator<<(StringBuilder &sb, const HttpQuery &q) {
switch (q.type_) {
case HttpQuery::Type::EMPTY:

View File

@ -38,6 +38,8 @@ class HttpQuery {
MutableSlice arg(Slice key) const;
std::vector<std::pair<string, string>> string_args() const;
int get_retry_after() const;
};
using HttpQueryPtr = std::unique_ptr<HttpQuery>;