Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(request): if host is ipv6 address, enclose it in square brackets #92

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading