Skip to content

Commit

Permalink
Fix incorrect LargeResponseHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
algesten committed Feb 18, 2025
1 parent dbc34b5 commit 7e41dff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,18 @@ pub(crate) mod test {
ensure!(Body, 700); // 648
}

#[test]
fn limit_max_response_header_size() {
init_test_log();
let err = get("http://httpbin.org/get")
.config()
.max_response_header_size(5)
.build()
.call()
.unwrap_err();
assert!(matches!(err, Error::LargeResponseHeader(65, 5)));
}

// This doesn't need to run, just compile.
fn _ensure_send_sync() {
fn is_send(_t: impl Send) {}
Expand Down
12 changes: 11 additions & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,17 @@ fn recv_response(

let (amount, maybe_response) = flow.try_response(input, allow_partial_redirect)?;

if input.len() > config.max_response_header_size() {
let check_size = if maybe_response.is_some() {
// We got a parsed response, ensure the size is within
// configured parameters.
amount
} else {
// We did not parse a response, if input is too large,
// we stop trying to get more data.
input.len()
};

if check_size > config.max_response_header_size() {
return Err(Error::LargeResponseHeader(
input.len(),
config.max_response_header_size(),
Expand Down

0 comments on commit 7e41dff

Please sign in to comment.