Skip to content

Commit

Permalink
Also display the scheme
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Levick <[email protected]>
  • Loading branch information
rylev committed Dec 5, 2023
1 parent acd8817 commit 396e343
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/outbound-http/src/host_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ impl outbound_http::Host for OutboundHttp {
.map_err(|_| HttpError::RuntimeError)?
{
tracing::log::info!("Destination not allowed: {}", req.uri);
if let Some(host_and_port) = host_and_port(&req.uri) {
if let Some((scheme, host_and_port)) = scheme_host_and_port(&req.uri) {
terminal::warn!("A component tried to make a HTTP request to non-allowed host '{host_and_port}'.");
eprintln!("To allow requests, add 'allowed_outbound_hosts = [\"https://{host_and_port}\"]' to the manifest component section.");
eprintln!("To allow requests, add 'allowed_outbound_hosts = [\"{scheme}://{host_and_port}\"]' to the manifest component section.");
}
return Err(HttpError::DestinationNotAllowed);
}
Expand Down Expand Up @@ -165,18 +165,18 @@ fn response_headers(h: &HeaderMap) -> anyhow::Result<Option<Vec<(String, String)
Ok(Some(res))
}

/// Return the `$HOST:$PORT` for the url string
/// Returns both the scheme and the `$HOST:$PORT` for the url string
///
/// Returns `None` if the url cannot be parsed or if it does not contain a host
fn host_and_port(url: &str) -> Option<String> {
fn scheme_host_and_port(url: &str) -> Option<(String, String)> {
url::Url::parse(url).ok().and_then(|u| {
u.host_str().map(|h| {
let mut host = h.to_owned();
if let Some(p) = u.port() {
use std::fmt::Write;
write!(&mut host, ":{p}").unwrap();
}
host
(u.scheme().to_owned(), host)
})
})
}

0 comments on commit 396e343

Please sign in to comment.