refactor(client): restore handshake to by-ref
This commit is contained in:
@@ -506,46 +506,50 @@ impl Builder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs a connection with the configured options and IO.
|
/// Constructs a connection with the configured options and IO.
|
||||||
pub async fn handshake<T, B>(self, io: T) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
|
pub fn handshake<T, B>(&self, io: T) -> impl Future<Output = crate::Result<(SendRequest<B>, Connection<T, B>)>>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
||||||
B: Payload + 'static,
|
B: Payload + 'static,
|
||||||
B::Data: Unpin,
|
B::Data: Unpin,
|
||||||
{
|
{
|
||||||
trace!("client handshake HTTP/{}", if self.http2 { 2 } else { 1 });
|
let opts = self.clone();
|
||||||
|
|
||||||
let (tx, rx) = dispatch::channel();
|
async move {
|
||||||
let either = if !self.http2 {
|
trace!("client handshake HTTP/{}", if opts.http2 { 2 } else { 1 });
|
||||||
let mut conn = proto::Conn::new(io);
|
|
||||||
if !self.h1_writev {
|
|
||||||
conn.set_write_strategy_flatten();
|
|
||||||
}
|
|
||||||
if self.h1_title_case_headers {
|
|
||||||
conn.set_title_case_headers();
|
|
||||||
}
|
|
||||||
if let Some(sz) = self.h1_read_buf_exact_size {
|
|
||||||
conn.set_read_buf_exact_size(sz);
|
|
||||||
}
|
|
||||||
if let Some(max) = self.h1_max_buf_size {
|
|
||||||
conn.set_max_buf_size(max);
|
|
||||||
}
|
|
||||||
let cd = proto::h1::dispatch::Client::new(rx);
|
|
||||||
let dispatch = proto::h1::Dispatcher::new(cd, conn);
|
|
||||||
Either::Left(dispatch)
|
|
||||||
} else {
|
|
||||||
let h2 = proto::h2::client::handshake(io, rx, &self.h2_builder, self.exec.clone())
|
|
||||||
.await?;
|
|
||||||
Either::Right(h2)
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok((
|
let (tx, rx) = dispatch::channel();
|
||||||
SendRequest {
|
let either = if !opts.http2 {
|
||||||
dispatch: tx,
|
let mut conn = proto::Conn::new(io);
|
||||||
},
|
if !opts.h1_writev {
|
||||||
Connection {
|
conn.set_write_strategy_flatten();
|
||||||
inner: Some(either),
|
}
|
||||||
},
|
if opts.h1_title_case_headers {
|
||||||
))
|
conn.set_title_case_headers();
|
||||||
|
}
|
||||||
|
if let Some(sz) = opts.h1_read_buf_exact_size {
|
||||||
|
conn.set_read_buf_exact_size(sz);
|
||||||
|
}
|
||||||
|
if let Some(max) = opts.h1_max_buf_size {
|
||||||
|
conn.set_max_buf_size(max);
|
||||||
|
}
|
||||||
|
let cd = proto::h1::dispatch::Client::new(rx);
|
||||||
|
let dispatch = proto::h1::Dispatcher::new(cd, conn);
|
||||||
|
Either::Left(dispatch)
|
||||||
|
} else {
|
||||||
|
let h2 = proto::h2::client::handshake(io, rx, &opts.h2_builder, opts.exec.clone())
|
||||||
|
.await?;
|
||||||
|
Either::Right(h2)
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok((
|
||||||
|
SendRequest {
|
||||||
|
dispatch: tx,
|
||||||
|
},
|
||||||
|
Connection {
|
||||||
|
inner: Some(either),
|
||||||
|
},
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -514,8 +514,6 @@ where C: Connect + Sync + 'static,
|
|||||||
let is_h2 = is_ver_h2 || connected.alpn == Alpn::H2;
|
let is_h2 = is_ver_h2 || connected.alpn == Alpn::H2;
|
||||||
Either::Left(Box::pin(conn_builder
|
Either::Left(Box::pin(conn_builder
|
||||||
.http2_only(is_h2)
|
.http2_only(is_h2)
|
||||||
// TODO: convert client::conn::Builder to be by-value?
|
|
||||||
.clone()
|
|
||||||
.handshake(io)
|
.handshake(io)
|
||||||
.and_then(move |(tx, conn)| {
|
.and_then(move |(tx, conn)| {
|
||||||
trace!("handshake complete, spawning background dispatcher task");
|
trace!("handshake complete, spawning background dispatcher task");
|
||||||
|
|||||||
Reference in New Issue
Block a user