diff --git a/td/mtproto/AuthData.h b/td/mtproto/AuthData.h index 7293ffd1c..6e6af1fb6 100644 --- a/td/mtproto/AuthData.h +++ b/td/mtproto/AuthData.h @@ -148,7 +148,7 @@ class AuthData { tmp_auth_key_.set_auth_flag(true); } - Slice header() { + Slice get_header() { if (use_pfs()) { return tmp_auth_key_.need_header() ? Slice(header_) : Slice(); } else { diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index 4b78d783f..ac4798048 100644 --- a/td/mtproto/SessionConnection.cpp +++ b/td/mtproto/SessionConnection.cpp @@ -869,9 +869,9 @@ void SessionConnection::flush_packet() { { uint64 parent_message_id = 0; auto storer = PacketStorer( - queries, auth_data_->header(), std::move(to_ack), ping_id, ping_disconnect_delay() + 2, max_delay, max_after, - max_wait, future_salt_n, to_get_state_info, to_resend_answer, to_cancel_answer, auth_data_, &container_id, - &get_state_info_id, &resend_answer_id, &ping_message_id, &parent_message_id); + queries, auth_data_->get_header(), std::move(to_ack), ping_id, ping_disconnect_delay() + 2, max_delay, + max_after, max_wait, future_salt_n, to_get_state_info, to_resend_answer, to_cancel_answer, auth_data_, + &container_id, &get_state_info_id, &resend_answer_id, &ping_message_id, &parent_message_id); auto quick_ack_token = use_quick_ack ? parent_message_id : 0; send_crypto(storer, quick_ack_token); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 3cd908f37..8f7aa4e4e 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1092,11 +1092,11 @@ class CliClient final : public Actor { LOG(ERROR) << status.error(); return; } - string bot_id = query.arg("bot_id").str(); - string scope = query.arg("scope").str(); - string public_key = query.arg("public_key").str(); - string payload = query.arg("payload").str(); - LOG(ERROR) << query.arg("callback_url"); + string bot_id = query.get_arg("bot_id").str(); + string scope = query.get_arg("scope").str(); + string public_key = query.get_arg("public_key").str(); + string payload = query.get_arg("payload").str(); + LOG(ERROR) << query.get_arg("callback_url"); send_request(make_tl_object(to_integer(bot_id), scope, public_key, payload, password)); } else if (op == "spaf") { diff --git a/tdnet/td/net/HttpQuery.cpp b/tdnet/td/net/HttpQuery.cpp index 9f557abe1..9a34b66b4 100644 --- a/tdnet/td/net/HttpQuery.cpp +++ b/tdnet/td/net/HttpQuery.cpp @@ -12,28 +12,29 @@ namespace td { -Slice HttpQuery::header(Slice key) const { +Slice HttpQuery::get_header(Slice key) const { auto it = std::find_if(headers_.begin(), headers_.end(), [&key](const std::pair &s) { return s.first == key; }); return it == headers_.end() ? Slice() : it->second; } -MutableSlice HttpQuery::arg(Slice key) const { +MutableSlice HttpQuery::get_arg(Slice key) const { auto it = std::find_if(args_.begin(), args_.end(), [&key](const std::pair &s) { return s.first == key; }); return it == args_.end() ? MutableSlice() : it->second; } -std::vector> HttpQuery::string_args() const { +std::vector> HttpQuery::get_args() const { std::vector> res; + res.reserve(args_.size()); for (auto &it : args_) { - res.push_back(std::make_pair(it.first.str(), it.second.str())); + res.emplace_back(it.first.str(), it.second.str()); } return res; } int HttpQuery::get_retry_after() const { - auto value = header("retry-after"); + auto value = get_header("retry-after"); if (value.empty()) { return 0; } diff --git a/tdnet/td/net/HttpQuery.h b/tdnet/td/net/HttpQuery.h index bb304556d..1bbf100f1 100644 --- a/tdnet/td/net/HttpQuery.h +++ b/tdnet/td/net/HttpQuery.h @@ -33,11 +33,11 @@ class HttpQuery { std::vector files_; MutableSlice content_; - Slice header(Slice key) const; + Slice get_header(Slice key) const; - MutableSlice arg(Slice key) const; + MutableSlice get_arg(Slice key) const; - std::vector> string_args() const; + std::vector> get_args() const; int get_retry_after() const; }; diff --git a/tdnet/td/net/Wget.cpp b/tdnet/td/net/Wget.cpp index b30128be3..29c6a2e70 100644 --- a/tdnet/td/net/Wget.cpp +++ b/tdnet/td/net/Wget.cpp @@ -52,16 +52,23 @@ Status Wget::try_init() { HttpHeaderCreator hc; hc.init_get(url.query_); bool was_host = false; + bool was_accept_encoding = false; for (auto &header : headers_) { - if (header.first == "Host") { // TODO: lowercase + auto header_lower = to_lower(header.first); + if (header_lower == "host") { was_host = true; } + if (header_lower == "accept-encoding") { + was_accept_encoding = true; + } hc.add_header(header.first, header.second); } if (!was_host) { hc.add_header("Host", url.host_); } - hc.add_header("Accept-Encoding", "gzip, deflate"); + if (!was_accept_encoding) { + hc.add_header("Accept-Encoding", "gzip, deflate"); + } send_closure(connection_, &HttpOutboundConnection::write_next, BufferSlice(hc.finish().ok())); send_closure(connection_, &HttpOutboundConnection::write_ok); @@ -89,7 +96,7 @@ void Wget::on_ok(HttpQueryPtr http_query_ptr) { CHECK(promise_); if (http_query_ptr->code_ == 302 && ttl_ > 0) { LOG(DEBUG) << *http_query_ptr; - input_url_ = http_query_ptr->header("location").str(); + input_url_ = http_query_ptr->get_header("location").str(); LOG(DEBUG) << input_url_; ttl_--; connection_.reset(); @@ -98,7 +105,7 @@ void Wget::on_ok(HttpQueryPtr http_query_ptr) { promise_.set_value(std::move(http_query_ptr)); stop(); } else { - on_error(Status::Error(PSLICE() << "http error: " << http_query_ptr->code_)); + on_error(Status::Error(PSLICE() << "HTTP error: " << http_query_ptr->code_)); } }