Skip to content

Commit

Permalink
Add experimental_http1_max_buf_size
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Nov 7, 2024
1 parent 2d3e901 commit 1969f11
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apollo-router/src/axum_factory/axum_http_server_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ impl HttpServerFactory for AxumHttpServerFactory {
if let Some(max_headers) = configuration.supergraph.experimental_http1_max_headers {
http_config.http1_max_headers(max_headers);
}
if let Some(max_buf_size) = configuration.supergraph.experimental_http1_max_buf_size {
http_config.max_buf_size(max_buf_size);
}

let (main_server, main_shutdown_sender) = serve_router_on_listen_addr(
main_listener,
Expand Down
9 changes: 9 additions & 0 deletions apollo-router/src/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,11 @@ pub(crate) struct Supergraph {
///
/// Default is 100.
pub(crate) experimental_http1_max_headers: Option<usize>,

/// Set the maximum buffer size for the HTTP1 connection.
///
/// Default is ~400kb.
pub(crate) experimental_http1_max_buf_size: Option<usize>,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
Expand Down Expand Up @@ -746,6 +751,7 @@ impl Supergraph {
early_cancel: Option<bool>,
experimental_log_on_broken_pipe: Option<bool>,
experimental_http1_max_headers: Option<usize>,
experimental_http1_max_buf_size: Option<usize>,
) -> Self {
Self {
listen: listen.unwrap_or_else(default_graphql_listen),
Expand All @@ -766,6 +772,7 @@ impl Supergraph {
early_cancel: early_cancel.unwrap_or_default(),
experimental_log_on_broken_pipe: experimental_log_on_broken_pipe.unwrap_or_default(),
experimental_http1_max_headers,
experimental_http1_max_buf_size,
}
}
}
Expand All @@ -785,6 +792,7 @@ impl Supergraph {
early_cancel: Option<bool>,
experimental_log_on_broken_pipe: Option<bool>,
experimental_http1_max_headers: Option<usize>,
experimental_http1_max_buf_size: Option<usize>,
) -> Self {
Self {
listen: listen.unwrap_or_else(test_listen),
Expand All @@ -805,6 +813,7 @@ impl Supergraph {
early_cancel: early_cancel.unwrap_or_default(),
experimental_log_on_broken_pipe: experimental_log_on_broken_pipe.unwrap_or_default(),
experimental_http1_max_headers,
experimental_http1_max_buf_size,
}
}
}
Expand Down
56 changes: 56 additions & 0 deletions apollo-router/tests/integration/supergraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,59 @@ async fn test_supergraph_allow_to_change_http1_max_headers() -> Result<(), BoxEr
);
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn test_supergraph_allow_to_change_http1_max_buf_size(
) -> Result<(), BoxError> {
let mut router = IntegrationTest::builder()
.config(
r#"
supergraph:
experimental_http1_max_buf_size: 1000000
"#,
)
.build()
.await;

router.start().await;
router.assert_started().await;

let mut headers = HashMap::new();
headers.insert(format!("test-header"), "x".repeat(1048576 + 1));

let (_trace_id, response) = router
.execute_query_with_headers(&json!({ "query": "{ __typename }"}), headers)
.await;
assert_eq!(response.status(), 431);
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn test_supergraph_errors_on_http1_header_that_does_not_fit_inside_buffer(
) -> Result<(), BoxError> {
let mut router = IntegrationTest::builder()
.config(
r#"
supergraph:
experimental_http1_max_buf_size: 2000000
"#,
)
.build()
.await;

router.start().await;
router.assert_started().await;

let mut headers = HashMap::new();
headers.insert(format!("test-header"), "x".repeat(1048576 + 1));

let (_trace_id, response) = router
.execute_query_with_headers(&json!({ "query": "{ __typename }"}), headers)
.await;
assert_eq!(response.status(), 200);
assert_eq!(
response.json::<serde_json::Value>().await?,
json!({ "data": { "__typename": "Query" } })
);
Ok(())
}

0 comments on commit 1969f11

Please sign in to comment.