Remove CRLF from Milter headers

This commit is contained in:
mdecimus 2023-08-04 16:19:01 +02:00
parent fe2e4079d3
commit a0ceaeba1c
3 changed files with 12 additions and 7 deletions

View file

@ -227,14 +227,14 @@ impl<T: AsyncRead + AsyncWrite + Unpin> MilterClient<T> {
pub async fn headers<I, H, V>(&mut self, headers: I) -> super::Result<Action> pub async fn headers<I, H, V>(&mut self, headers: I) -> super::Result<Action>
where where
I: Iterator<Item = (H, V)>, I: Iterator<Item = (H, V)>,
H: AsRef<[u8]>, H: AsRef<str>,
V: AsRef<[u8]>, V: AsRef<str>,
{ {
if !self.has_option(SMFIP_NOHDRS) { if !self.has_option(SMFIP_NOHDRS) {
for (name, value) in headers { for (name, value) in headers {
self.write(Command::Header { self.write(Command::Header {
name: name.as_ref(), name: name.as_ref().trim().as_bytes(),
value: value.as_ref(), value: value.as_ref().trim().as_bytes(),
}) })
.await?; .await?;
if !self.has_option(SMFIP_NR_HDR) { if !self.has_option(SMFIP_NR_HDR) {

View file

@ -219,7 +219,12 @@ impl<T: AsyncWrite + AsyncRead + IsTls + Unpin> Session<T> {
// Headers // Headers
client client
.headers(message.raw_parsed_headers().iter().cloned()) .headers(message.raw_parsed_headers().iter().map(|(k, v)| {
(
std::str::from_utf8(k).unwrap_or_default(),
std::str::from_utf8(v).unwrap_or_default(),
)
}))
.await? .await?
.assert_continue()?; .assert_continue()?;

View file

@ -377,9 +377,9 @@ async fn milter_client_test() {
let mut client = MilterClient::connect( let mut client = MilterClient::connect(
&Milter { &Milter {
enable: IfBlock::default(), enable: IfBlock::default(),
addrs: vec![SocketAddr::from(([127, 0, 0, 1], 1234))], addrs: vec![SocketAddr::from(([127, 0, 0, 1], 11332))],
hostname: "localhost".to_string(), hostname: "localhost".to_string(),
port: 1234, port: 11332,
timeout_connect: Duration::from_secs(10), timeout_connect: Duration::from_secs(10),
timeout_command: Duration::from_secs(30), timeout_command: Duration::from_secs(30),
timeout_data: Duration::from_secs(30), timeout_data: Duration::from_secs(30),