Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into http1-send-trailers
Browse files Browse the repository at this point in the history
  • Loading branch information
hjr3 committed Apr 24, 2024
2 parents 545f8c4 + 226305d commit 8d91e7f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
6 changes: 2 additions & 4 deletions src/proto/h1/conn.rs
Expand Up @@ -277,8 +277,7 @@ where
.head
.headers
.get(TE)
.map(|te_header| te_header == "trailers")
.unwrap_or(false);
.map_or(false, |te_header| te_header == "trailers");

Poll::Ready(Some(Ok((msg.head, msg.decode, wants))))
}
Expand Down Expand Up @@ -603,8 +602,7 @@ where
let outgoing_is_keep_alive = head
.headers
.get(CONNECTION)
.map(connection_keep_alive)
.unwrap_or(false);
.map_or(false, connection_keep_alive);

if !outgoing_is_keep_alive {
match head.version {
Expand Down
17 changes: 13 additions & 4 deletions src/proto/h1/encode.rs
Expand Up @@ -165,6 +165,7 @@ impl Encoder {
trailers: HeaderMap,
title_case_headers: bool,
) -> Option<EncodedBuf<B>> {
trace!("encoding trailers");
match &self.kind {
Kind::Chunked(Some(ref allowed_trailer_fields)) => {
let allowed_trailer_field_map = allowed_trailer_field_map(&allowed_trailer_fields);
Expand All @@ -178,10 +179,14 @@ impl Encoder {
}
let name = cur_name.as_ref().expect("current header name");

if allowed_trailer_field_map.contains_key(name.as_str())
&& is_valid_trailer_field(name)
{
allowed_trailers.insert(name, value);
if allowed_trailer_field_map.contains_key(name.as_str()) {
if is_valid_trailer_field(name) {
allowed_trailers.insert(name, value);
} else {
debug!("trailer field is not valid: {}", &name);
}
} else {
debug!("trailer header name not found in trailer header: {}", &name);
}
}

Expand All @@ -200,6 +205,10 @@ impl Encoder {
kind: BufKind::Trailers(b"0\r\n".chain(Bytes::from(buf)).chain(b"\r\n")),
})
}
Kind::Chunked(None) => {
debug!("attempted to encode trailers, but the trailer header is not set");
None
}
_ => {
debug!("attempted to encode trailers for non-chunked response");
None
Expand Down
8 changes: 4 additions & 4 deletions src/proto/h1/io.rs
Expand Up @@ -450,7 +450,7 @@ fn prev_power_of_two(n: usize) -> usize {
// Only way this shift can underflow is if n is less than 4.
// (Which would means `usize::MAX >> 64` and underflowed!)
debug_assert!(n >= 4);
(::std::usize::MAX >> (n.leading_zeros() + 2)) + 1
(usize::MAX >> (n.leading_zeros() + 2)) + 1
}

impl Default for ReadStrategy {
Expand Down Expand Up @@ -763,7 +763,7 @@ mod tests {
assert_eq!(strategy.next(), 32768);

// Enormous records still increment at same rate
strategy.record(::std::usize::MAX);
strategy.record(usize::MAX);
assert_eq!(strategy.next(), 65536);

let max = strategy.max();
Expand Down Expand Up @@ -833,7 +833,7 @@ mod tests {
fn fuzz(max: usize) {
let mut strategy = ReadStrategy::with_max(max);
while strategy.next() < max {
strategy.record(::std::usize::MAX);
strategy.record(usize::MAX);
}
let mut next = strategy.next();
while next > 8192 {
Expand All @@ -854,7 +854,7 @@ mod tests {
fuzz(max);
max = (max / 2).saturating_mul(3);
}
fuzz(::std::usize::MAX);
fuzz(usize::MAX);
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions src/proto/h2/mod.rs
Expand Up @@ -54,8 +54,7 @@ fn strip_connection_headers(headers: &mut HeaderMap, is_request: bool) {
if is_request {
if headers
.get(TE)
.map(|te_header| te_header != "trailers")
.unwrap_or(false)
.map_or(false, |te_header| te_header != "trailers")
{
warn!("TE headers not set to \"trailers\" are illegal in HTTP/2 requests");
headers.remove(TE);
Expand Down

0 comments on commit 8d91e7f

Please sign in to comment.