Fix HeaderCreator usage.

GitOrigin-RevId: 1ac210190048ad2797751630a838f74541dda37d
This commit is contained in:
levlam 2018-06-01 23:45:34 +03:00
parent 56a2cac6ba
commit e11d4e02db
2 changed files with 18 additions and 19 deletions

View File

@ -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();

View File

@ -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());
send_closure(connection_, &HttpOutboundConnection::write_next, BufferSlice(hc.finish().ok()));
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(header));
send_closure(connection_, &HttpOutboundConnection::write_ok);
return Status::OK();
}