Don't run headers that don't need encoding though the encoder (#739)
This commit is contained in:
@@ -36,7 +36,8 @@ impl Header for ContentTransferEncoding {
|
||||
}
|
||||
|
||||
fn display(&self) -> HeaderValue {
|
||||
HeaderValue::new(Self::name(), self.to_string())
|
||||
let val = self.to_string();
|
||||
HeaderValue::dangerous_new_pre_encoded(Self::name(), val.clone(), val)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,17 +44,17 @@ impl Header for Date {
|
||||
}
|
||||
|
||||
fn display(&self) -> HeaderValue {
|
||||
let mut s = self.0.to_string();
|
||||
if s.ends_with(" GMT") {
|
||||
let mut val = self.0.to_string();
|
||||
if val.ends_with(" GMT") {
|
||||
// The httpdate crate always appends ` GMT` to the end of the string,
|
||||
// but this is considered an obsolete date format for email
|
||||
// https://tools.ietf.org/html/rfc2822#appendix-A.6.2,
|
||||
// so we replace `GMT` with `-0000`
|
||||
s.truncate(s.len() - "GMT".len());
|
||||
s.push_str("-0000");
|
||||
val.truncate(val.len() - "GMT".len());
|
||||
val.push_str("-0000");
|
||||
}
|
||||
|
||||
HeaderValue::new(Self::name(), s)
|
||||
HeaderValue::dangerous_new_pre_encoded(Self::name(), val.clone(), val)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,8 @@ impl Header for MimeVersion {
|
||||
}
|
||||
|
||||
fn display(&self) -> HeaderValue {
|
||||
HeaderValue::new(Self::name(), format!("{}.{}", self.major, self.minor))
|
||||
let val = format!("{}.{}", self.major, self.minor);
|
||||
HeaderValue::dangerous_new_pre_encoded(Self::name(), val.clone(), val)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user