mirror of https://github.com/fafhrd91/actix-web
add defaults for http2 client configuration
This commit is contained in:
parent
795a575fc5
commit
8546b412d9
|
@ -1,11 +1,12 @@
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::time;
|
use std::time;
|
||||||
|
use std::future::Future;
|
||||||
|
|
||||||
use actix_codec::{AsyncRead, AsyncWrite};
|
use actix_codec::{AsyncRead, AsyncWrite};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_util::future::poll_fn;
|
use futures_util::future::poll_fn;
|
||||||
use futures_util::pin_mut;
|
use futures_util::pin_mut;
|
||||||
use h2::{client::SendRequest, SendStream};
|
use h2::{client::{SendRequest, Connection, Builder}, SendStream};
|
||||||
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, TRANSFER_ENCODING};
|
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, TRANSFER_ENCODING};
|
||||||
use http::{request::Request, Method, Version};
|
use http::{request::Request, Method, Version};
|
||||||
|
|
||||||
|
@ -185,3 +186,21 @@ fn release<T: AsyncRead + AsyncWrite + Unpin + 'static>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// These values are taken from hyper/src/proto/h2/client.rs
|
||||||
|
const DEFAULT_H2_CONN_WINDOW: u32 = 1024 * 1024 * 5; // 5mb
|
||||||
|
const DEFAULT_H2_STREAM_WINDOW: u32 = 1024 * 1024 * 2; // 2mb
|
||||||
|
|
||||||
|
pub(crate) fn handshake<Io>(io: Io)
|
||||||
|
-> impl Future<Output=Result<(SendRequest<Bytes>, Connection<Io, Bytes>), h2::Error>>
|
||||||
|
where
|
||||||
|
Io: AsyncRead + AsyncWrite + Unpin + 'static,
|
||||||
|
{
|
||||||
|
let mut builder = Builder::new();
|
||||||
|
builder
|
||||||
|
.initial_window_size(DEFAULT_H2_CONN_WINDOW)
|
||||||
|
.initial_connection_window_size(DEFAULT_H2_STREAM_WINDOW)
|
||||||
|
.enable_push(false);
|
||||||
|
builder.handshake(io)
|
||||||
|
}
|
||||||
|
|
|
@ -13,12 +13,13 @@ use actix_utils::{oneshot, task::LocalWaker};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_util::future::{poll_fn, FutureExt, LocalBoxFuture};
|
use futures_util::future::{poll_fn, FutureExt, LocalBoxFuture};
|
||||||
use fxhash::FxHashMap;
|
use fxhash::FxHashMap;
|
||||||
use h2::client::{handshake, Connection, SendRequest};
|
use h2::client::{Connection, SendRequest};
|
||||||
use http::uri::Authority;
|
use http::uri::Authority;
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
use pin_project::pin_project;
|
use pin_project::pin_project;
|
||||||
use slab::Slab;
|
use slab::Slab;
|
||||||
|
|
||||||
|
use super::h2proto::handshake;
|
||||||
use super::connection::{ConnectionType, IoConnection};
|
use super::connection::{ConnectionType, IoConnection};
|
||||||
use super::error::ConnectError;
|
use super::error::ConnectError;
|
||||||
use super::Connect;
|
use super::Connect;
|
||||||
|
@ -593,7 +594,7 @@ where
|
||||||
Some(Acquired(this.key.clone(), this.inner.take())),
|
Some(Acquired(this.key.clone(), this.inner.take())),
|
||||||
)));
|
)));
|
||||||
Poll::Ready(())
|
Poll::Ready(())
|
||||||
} else {
|
} else {
|
||||||
*this.h2 = Some(handshake(io).boxed_local());
|
*this.h2 = Some(handshake(io).boxed_local());
|
||||||
self.poll(cx)
|
self.poll(cx)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue