Skip to content

Commit

Permalink
Fix HeaderCreator usage.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 1ac210190048ad2797751630a838f74541dda37d
  • Loading branch information
levlam committed Jun 1, 2018
1 parent 56a2cac commit e11d4e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
4 changes: 1 addition & 3 deletions td/mtproto/HttpTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ void Transport::write(BufferWriter &&message, bool quick_ack) {
hc.set_keep_alive();
hc.set_content_size(message.size());
auto r_head = hc.finish();
if (r_head.is_error()) {
UNREACHABLE();
}
CHECK(r_head.is_ok());
Slice src = r_head.ok();
MutableSlice dst = message.prepare_prepend();
CHECK(dst.size() >= src.size()) << dst.size() << " >= " << src.size();
Expand Down
33 changes: 17 additions & 16 deletions tdnet/td/net/Wget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down

0 comments on commit e11d4e0

Please sign in to comment.