add defaults for http2 client configuration

This commit is contained in:
Maksym Vorobiov 2020-03-03 18:01:16 +02:00
parent 795a575fc5
commit 8546b412d9
2 changed files with 23 additions and 3 deletions

View File

@ -1,11 +1,12 @@
use std::convert::TryFrom;
use std::time;
use std::future::Future;
use actix_codec::{AsyncRead, AsyncWrite};
use bytes::Bytes;
use futures_util::future::poll_fn;
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::{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)
}

View File

@ -13,12 +13,13 @@ use actix_utils::{oneshot, task::LocalWaker};
use bytes::Bytes;
use futures_util::future::{poll_fn, FutureExt, LocalBoxFuture};
use fxhash::FxHashMap;
use h2::client::{handshake, Connection, SendRequest};
use h2::client::{Connection, SendRequest};
use http::uri::Authority;
use indexmap::IndexSet;
use pin_project::pin_project;
use slab::Slab;
use super::h2proto::handshake;
use super::connection::{ConnectionType, IoConnection};
use super::error::ConnectError;
use super::Connect;