Skip to content

Commit

Permalink
Params -> Config
Browse files Browse the repository at this point in the history
  • Loading branch information
eagr committed Dec 7, 2022
1 parent e4e207f commit 3b76471
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 40 deletions.
22 changes: 11 additions & 11 deletions h3/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use http::{request, HeaderMap, Response};
use tracing::{info, trace};

use crate::{
config::Config,
connection::{self, ConnectionInner, ConnectionState, SharedStateRef},
error::{Code, Error, ErrorLevel},
frame::FrameStream,
params::Params,
proto::{frame::Frame, headers::Header},
qpack, quic, stream,
};

/// Start building a new HTTP/3 client with default params
/// Start building a new HTTP/3 client with default config
pub fn builder() -> Builder {
Builder::new(Default::default())
}
Expand Down Expand Up @@ -470,22 +470,22 @@ where
/// # O: quic::OpenStreams<B>,
/// # B: bytes::Buf,
/// # {
/// let params = h3::params::Params::default()
/// let config = h3::Config::new()
/// .max_field_section_size(8192);
/// let h3_conn = h3::client::Builder::new(params)
/// let h3_conn = h3::client::Builder::new(config)
/// .build(quic)
/// .await
/// .expect("Failed to build connection");
/// # }
/// ```
pub struct Builder {
params: Params,
config: Config,
}

impl Builder {
/// Create a HTTP/3 client builder
pub fn new(params: Params) -> Self {
Self { params }
pub fn new(config: Config) -> Self {
Self { config }
}

/// Create a new HTTP/3 client from a `quic` connection
Expand All @@ -507,20 +507,20 @@ impl Builder {
Connection {
inner: ConnectionInner::new(
quic,
self.params.max_field_section_size,
self.config.max_field_section_size,
conn_state.clone(),
self.params.grease,
self.config.grease,
)
.await?,
},
SendRequest {
open,
conn_state,
conn_waker,
max_field_section_size: self.params.max_field_section_size,
max_field_section_size: self.config.max_field_section_size,
sender_count: Arc::new(AtomicUsize::new(1)),
_buf: PhantomData,
send_grease_frame: self.params.grease,
send_grease_frame: self.config.grease,
},
))
}
Expand Down
11 changes: 8 additions & 3 deletions h3/src/params.rs → h3/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
/// HTTP/3 connection parameters builder
#[derive(Debug)]
pub struct Params {
pub struct Config {
pub(crate) enable_webtransport: bool,
pub(crate) grease: bool,
pub(crate) max_field_section_size: u64,
}

impl Default for Params {
impl Default for Config {
fn default() -> Self {
Self {
enable_webtransport: false,
Expand All @@ -18,10 +18,15 @@ impl Default for Params {
}
}

impl Params {
impl Config {
/// Default max header size
pub const DEFAULT_MAX_FIELD_SECTION_SIZE: u64 = (1 << 62) - 1;

/// Start to create config
pub fn new() -> Self {
Self::default()
}

/// Enable WebTransport
pub fn enable_webtransport(mut self) -> Self {
self.enable_webtransport = true;
Expand Down
3 changes: 2 additions & 1 deletion h3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#![allow(clippy::derive_partial_eq_without_eq)]

pub mod client;
pub mod config;
pub mod error;
pub mod params;
pub mod quic;
pub mod server;

pub use error::Error;
pub use config::Config;

mod buf;
mod connection;
Expand Down
20 changes: 10 additions & 10 deletions h3/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ use quic::StreamId;
use tokio::sync::mpsc;

use crate::{
config::Config,
connection::{self, ConnectionInner, ConnectionState, SharedStateRef},
error::{Code, Error, ErrorLevel},
frame::FrameStream,
params::Params,
proto::{frame::Frame, headers::Header},
qpack,
quic::{self, RecvStream as _, SendStream as _},
Expand Down Expand Up @@ -493,24 +493,24 @@ where
/// C: h3::quic::Connection<B>,
/// B: bytes::Buf,
/// {
/// let params = h3::params::Params::default()
/// let config = h3::Config::new()
/// // Set the maximum header size
/// .max_field_section_size(1000)
/// // do not send grease types
/// .grease(false);
/// let mut server_builder = h3::server::Builder::new(params);
/// .disable_grease();
/// let mut server_builder = h3::server::Builder::new(config);
/// // Build the Connection
/// let mut h3_conn = server_builder.build(conn);
/// }
/// ```
pub struct Builder {
pub(super) params: Params,
pub(super) config: Config,
}

impl Builder {
/// Create a new HTTP/3 server [`Builder`]
pub fn new(params: Params) -> Self {
Self { params }
pub fn new(config: Config) -> Self {
Self { config }
}
}

Expand All @@ -527,12 +527,12 @@ impl Builder {
Ok(Connection {
inner: ConnectionInner::new(
conn,
self.params.max_field_section_size,
self.config.max_field_section_size,
SharedStateRef::default(),
self.params.grease,
self.config.grease,
)
.await?,
max_field_section_size: self.params.max_field_section_size,
max_field_section_size: self.config.max_field_section_size,
request_end_send: sender,
request_end_recv: receiver,
ongoing_streams: HashSet::new(),
Expand Down
6 changes: 3 additions & 3 deletions h3/src/tests/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use http::{Request, Response, StatusCode};

use crate::{
client::{self, SendRequest},
config::Config,
connection::ConnectionState,
error::{Code, Error, Kind},
params::Params,
proto::{
coding::Encode as _,
frame::{Frame, Settings},
Expand Down Expand Up @@ -162,7 +162,7 @@ async fn settings_exchange_client() {

let server_fut = async {
let conn = server.next().await;
let params = Params::default().max_field_section_size(12);
let params = Config::new().max_field_section_size(12);
let mut incoming = server::Builder::new(params).build(conn).await.unwrap();
incoming.accept().await.unwrap()
};
Expand All @@ -177,7 +177,7 @@ async fn settings_exchange_server() {
let mut server = pair.server();

let client_fut = async {
let params = Params::default().max_field_section_size(12);
let params = Config::new().max_field_section_size(12);
let (mut conn, _client) = client::Builder::new(params)
.build::<_, _, Bytes>(pair.client().await)
.await
Expand Down
24 changes: 12 additions & 12 deletions h3/src/tests/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use http::{request, HeaderMap, Request, Response, StatusCode};

use crate::{
client,
config::Config,
connection::ConnectionState,
error::{Code, Error, Kind},
params::Params,
proto::{
coding::Encode,
frame::{self, Frame, FrameType},
Expand Down Expand Up @@ -283,8 +283,8 @@ async fn header_too_big_response_from_server() {
//= type=test
//# An HTTP/3 implementation MAY impose a limit on the maximum size of
//# the message header it will accept on an individual HTTP message.
let params = Params::default().max_field_section_size(12);
let mut incoming_req = server::Builder::new(params).build(conn).await.unwrap();
let config = Config::new().max_field_section_size(12);
let mut incoming_req = server::Builder::new(config).build(conn).await.unwrap();

let err_kind = incoming_req.accept().await.map(|_| ()).unwrap_err().kind();
assert_matches!(
Expand Down Expand Up @@ -338,8 +338,8 @@ async fn header_too_big_response_from_server_trailers() {
//= type=test
//# An HTTP/3 implementation MAY impose a limit on the maximum size of
//# the message header it will accept on an individual HTTP message.
let params = Params::default().max_field_section_size(207);
let mut incoming_req = server::Builder::new(params).build(conn).await.unwrap();
let config = Config::new().max_field_section_size(207);
let mut incoming_req = server::Builder::new(config).build(conn).await.unwrap();

let (_request, mut request_stream) = incoming_req.accept().await.expect("accept").unwrap();
let _ = request_stream
Expand Down Expand Up @@ -403,8 +403,8 @@ async fn header_too_big_client_error() {
//= type=test
//# An HTTP/3 implementation MAY impose a limit on the maximum size of
//# the message header it will accept on an individual HTTP message.
let params = Params::default().max_field_section_size(12);
server::Builder::new(params).build(conn).await.unwrap();
let config = Config::new().max_field_section_size(12);
server::Builder::new(config).build(conn).await.unwrap();
};

tokio::join!(server_fut, client_fut);
Expand Down Expand Up @@ -463,8 +463,8 @@ async fn header_too_big_client_error_trailer() {
//= type=test
//# An HTTP/3 implementation MAY impose a limit on the maximum size of
//# the message header it will accept on an individual HTTP message.
let params = Params::default().max_field_section_size(207);
let mut incoming_req = server::Builder::new(params).build(conn).await.unwrap();
let config = Config::new().max_field_section_size(207);
let mut incoming_req = server::Builder::new(config).build(conn).await.unwrap();

let (_request, mut request_stream) = incoming_req.accept().await.expect("accept").unwrap();
let _ = request_stream
Expand Down Expand Up @@ -493,8 +493,8 @@ async fn header_too_big_discard_from_client() {
//# process it.

// Do not poll driver so client doesn't know about server's max_field section size setting
let params = Params::default().max_field_section_size(12);
let (_conn, mut client) = client::Builder::new(params)
let config = Config::new().max_field_section_size(12);
let (_conn, mut client) = client::Builder::new(config)
.build::<_, _, Bytes>(pair.client().await)
.await
.expect("client init");
Expand Down Expand Up @@ -578,7 +578,7 @@ async fn header_too_big_discard_from_client_trailers() {
//# process it.

// Do not poll driver so client doesn't know about server's max_field section size setting
let params = Params::default().max_field_section_size(200);
let params = Config::new().max_field_section_size(200);
let (mut driver, mut client) = client::Builder::new(params)
.build::<_, _, Bytes>(pair.client().await)
.await
Expand Down

0 comments on commit 3b76471

Please sign in to comment.