Keep connection header for 3 seconds after successful response.

This commit is contained in:
levlam 2022-01-06 21:19:07 +03:00
parent dd48b43769
commit dd1e0af5dc
2 changed files with 14 additions and 7 deletions

View File

@ -162,17 +162,19 @@ class AuthData {
return main_auth_key_.need_header() ? Slice(header_) : Slice(); return main_auth_key_.need_header() ? Slice(header_) : Slice();
} }
} }
void set_header(std::string header) { void set_header(std::string header) {
header_ = std::move(header); header_ = std::move(header);
} }
void on_api_response() { void on_api_response() {
if (use_pfs()) { if (use_pfs()) {
if (tmp_auth_key_.auth_flag()) { if (tmp_auth_key_.auth_flag()) {
tmp_auth_key_.set_need_header(false); tmp_auth_key_.remove_header();
} }
} else { } else {
if (main_auth_key_.auth_flag()) { if (main_auth_key_.auth_flag()) {
main_auth_key_.set_need_header(false); main_auth_key_.remove_header();
} }
} }
} }

View File

@ -39,11 +39,15 @@ class AuthKey {
} }
bool need_header() const { bool need_header() const {
return need_header_; return have_header_ || Time::now() < header_expires_at_;
} }
void set_need_header(bool need_header) { void remove_header() {
need_header_ = need_header; if (have_header_) {
have_header_ = false;
header_expires_at_ = Time::now() + 3;
}
} }
double expires_at() const { double expires_at() const {
return expires_at_; return expires_at_;
} }
@ -86,14 +90,15 @@ class AuthKey {
created_at_ = parser.fetch_double(); created_at_ = parser.fetch_double();
} }
// just in case // just in case
need_header_ = true; have_header_ = true;
} }
private: private:
uint64 auth_key_id_{0}; uint64 auth_key_id_{0};
string auth_key_; string auth_key_;
bool auth_flag_{false}; bool auth_flag_{false};
bool need_header_{true}; bool have_header_{true};
double header_expires_at_{0};
double expires_at_{0}; double expires_at_{0};
double created_at_{0}; double created_at_{0};
}; };