diff options
| author | levlam <levlam@telegram.org> | 2018-06-01 23:45:34 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2018-06-01 23:45:34 +0300 |
| commit | e11d4e02db7f1fd529ae668ee8b14e4d5912cfde (patch) | |
| tree | 72b4ef49635f738e9d374321b775d51d52e6e438 /tdnet/td/net/Wget.cpp | |
| parent | 56a2cac6baca719766b859aa666835b8aa7372f2 (diff) | |
Fix HeaderCreator usage.
GitOrigin-RevId: 1ac210190048ad2797751630a838f74541dda37d
Diffstat (limited to 'tdnet/td/net/Wget.cpp')
| -rw-r--r-- | tdnet/td/net/Wget.cpp | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/tdnet/td/net/Wget.cpp b/tdnet/td/net/Wget.cpp index 1818fa488..fb7f43c4e 100644 --- a/tdnet/td/net/Wget.cpp +++ b/tdnet/td/net/Wget.cpp @@ -38,21 +38,6 @@ Status Wget::try_init() { TRY_RESULT(ascii_host, idn_to_ascii(url.host_)); url.host_ = std::move(ascii_host); - IPAddress addr; - TRY_STATUS(addr.init_host_port(url.host_, url.port_)); - - TRY_RESULT(fd, SocketFd::open(addr)); - if (url.protocol_ == HttpUrl::Protocol::HTTP) { - connection_ = - create_actor<HttpOutboundConnection>("Connect", std::move(fd), std::numeric_limits<std::size_t>::max(), 0, 0, - ActorOwn<HttpOutboundConnection::Callback>(actor_id(this))); - } else { - TRY_RESULT(ssl_fd, SslFd::init(std::move(fd), url.host_, CSlice() /* certificate */, verify_peer_)); - connection_ = - create_actor<HttpOutboundConnection>("Connect", std::move(ssl_fd), std::numeric_limits<std::size_t>::max(), 0, - 0, ActorOwn<HttpOutboundConnection::Callback>(actor_id(this))); - } - HttpHeaderCreator hc; hc.init_get(url.query_); bool was_host = false; @@ -73,8 +58,24 @@ Status Wget::try_init() { if (!was_accept_encoding) { hc.add_header("Accept-Encoding", "gzip, deflate"); } + TRY_RESULT(header, hc.finish()); + + IPAddress addr; + TRY_STATUS(addr.init_host_port(url.host_, url.port_)); + + TRY_RESULT(fd, SocketFd::open(addr)); + if (url.protocol_ == HttpUrl::Protocol::HTTP) { + connection_ = + create_actor<HttpOutboundConnection>("Connect", std::move(fd), std::numeric_limits<std::size_t>::max(), 0, 0, + ActorOwn<HttpOutboundConnection::Callback>(actor_id(this))); + } else { + TRY_RESULT(ssl_fd, SslFd::init(std::move(fd), url.host_, CSlice() /* certificate */, verify_peer_)); + connection_ = + create_actor<HttpOutboundConnection>("Connect", std::move(ssl_fd), std::numeric_limits<std::size_t>::max(), 0, + 0, ActorOwn<HttpOutboundConnection::Callback>(actor_id(this))); + } - send_closure(connection_, &HttpOutboundConnection::write_next, BufferSlice(hc.finish().ok())); + send_closure(connection_, &HttpOutboundConnection::write_next, BufferSlice(header)); send_closure(connection_, &HttpOutboundConnection::write_ok); return Status::OK(); } |
