From 05d17c3396abfc58a933f77288dd933bf6dd3e12 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 19 Apr 2018 15:03:10 +0300 Subject: [PATCH] Support Retry-After. GitOrigin-RevId: ca7cf22cf166aa75bb9266faa3b5d04df3c2ec5b --- tdnet/td/net/HttpQuery.cpp | 15 +++++++++++++++ tdnet/td/net/HttpQuery.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/tdnet/td/net/HttpQuery.cpp b/tdnet/td/net/HttpQuery.cpp index b4af0eef..9f557abe 100644 --- a/tdnet/td/net/HttpQuery.cpp +++ b/tdnet/td/net/HttpQuery.cpp @@ -6,6 +6,8 @@ // #include "td/net/HttpQuery.h" +#include "td/utils/misc.h" + #include namespace td { @@ -30,6 +32,19 @@ std::vector> 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(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: diff --git a/tdnet/td/net/HttpQuery.h b/tdnet/td/net/HttpQuery.h index acab74ac..bb304556 100644 --- a/tdnet/td/net/HttpQuery.h +++ b/tdnet/td/net/HttpQuery.h @@ -38,6 +38,8 @@ class HttpQuery { MutableSlice arg(Slice key) const; std::vector> string_args() const; + + int get_retry_after() const; }; using HttpQueryPtr = std::unique_ptr;