Skip to content

Commit 226305d

Browse files
hjr3seanmonstar
authored andcommitted
fix(http1): improve debug messages when sending trailers
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.
1 parent e2d451e commit 226305d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/proto/h1/encode.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ impl Encoder {
165165
trailers: HeaderMap,
166166
title_case_headers: bool,
167167
) -> Option<EncodedBuf<B>> {
168+
trace!("encoding trailers");
168169
match &self.kind {
169170
Kind::Chunked(Some(ref allowed_trailer_fields)) => {
170171
let allowed_trailer_field_map = allowed_trailer_field_map(&allowed_trailer_fields);
@@ -178,10 +179,14 @@ impl Encoder {
178179
}
179180
let name = cur_name.as_ref().expect("current header name");
180181

181-
if allowed_trailer_field_map.contains_key(name.as_str())
182-
&& is_valid_trailer_field(name)
183-
{
184-
allowed_trailers.insert(name, value);
182+
if allowed_trailer_field_map.contains_key(name.as_str()) {
183+
if is_valid_trailer_field(name) {
184+
allowed_trailers.insert(name, value);
185+
} else {
186+
debug!("trailer field is not valid: {}", &name);
187+
}
188+
} else {
189+
debug!("trailer header name not found in trailer header: {}", &name);
185190
}
186191
}
187192

@@ -200,6 +205,10 @@ impl Encoder {
200205
kind: BufKind::Trailers(b"0\r\n".chain(Bytes::from(buf)).chain(b"\r\n")),
201206
})
202207
}
208+
Kind::Chunked(None) => {
209+
debug!("attempted to encode trailers, but the trailer header is not set");
210+
None
211+
}
203212
_ => {
204213
debug!("attempted to encode trailers for non-chunked response");
205214
None

0 commit comments

Comments
 (0)