Skip to content

Commit

Permalink
fix(http1): improve debug messages when sending trailers
Browse files Browse the repository at this point in the history
When the "trailer" header was not found in the response, the debug
message would say "attempted to encode trailers for non-chunked
response". This was quite misleading as the response was chunked. We
now include a better debug message that hints to the user that the
"trailer" header was not specified.

When a chunked response contained a trailer header that did not match
the header names specified in the "trailer" response header, there was
no debug message to the user. We now include debug messages that tell
the user if the header name is not allowed and if the header name was
not specified in the "trailer" response header.
  • Loading branch information
hjr3 authored and seanmonstar committed Apr 20, 2024
1 parent e2d451e commit 226305d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/proto/h1/encode.rs
Original file line number Diff line number Diff line change
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

0 comments on commit 226305d

Please sign in to comment.