Skip to content

Commit

Permalink
fix(request): if host is ipv6 address, enclose it in square brackets
Browse files Browse the repository at this point in the history
Related RFC requires it this way, and also at least apache would reject
non-bracketed ipv6 host address with Bad Request.
  • Loading branch information
elrafoon committed Oct 8, 2024
1 parent 9b53271 commit 9ce4120
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
use crate::headers::ContentType;
use crate::Error;
use core::fmt::Write as _;
use core::net::Ipv6Addr;
use core::str::FromStr;
use embedded_io::Error as _;
use embedded_io_async::Write;
use heapless::String;
Expand Down Expand Up @@ -139,7 +141,17 @@ where
}
}
if let Some(host) = &self.host {
write_header(c, "Host", host).await?;
let is_ipv6 = Ipv6Addr::from_str(host).is_ok();
write_str(c, "Host").await?;
write_str(c, ": ").await?;
if is_ipv6 {
write_str(c, "[").await?;
}
write_str(c, host).await?;
if is_ipv6 {
write_str(c, "]").await?;
}
write_str(c, "\r\n").await?;
}
if let Some(content_type) = &self.content_type {
write_header(c, "Content-Type", content_type.as_str()).await?;
Expand Down

0 comments on commit 9ce4120

Please sign in to comment.