Skip to content

Commit

Permalink
Tweaked message for blocked HTTP host
Browse files Browse the repository at this point in the history
Signed-off-by: itowlson <[email protected]>
  • Loading branch information
itowlson committed Oct 3, 2023
1 parent 6f35ce5 commit ca555e1
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crates/outbound-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ impl outbound_http::Host for OutboundHttp {
.map_err(|_| HttpError::RuntimeError)?
{
tracing::log::info!("Destination not allowed: {}", req.uri);
terminal::warn!("A component tried to make a HTTP request to '{}'.", req.uri);
eprintln!("The component was configured not to allow requests to this host.");
eprintln!("To allow requests, add the host to `allowed_http_posts`.");
if let Some(host) = host(&req.uri) {
terminal::warn!("A component tried to make a HTTP request to non-allowed host '{host}'.");
eprintln!("To allow requests, add 'allowed_http_hosts = [\"{host}\"]' to the component manifest.");
}
return Err(HttpError::DestinationNotAllowed);
}

Expand Down Expand Up @@ -170,3 +171,9 @@ fn response_headers(h: &HeaderMap) -> anyhow::Result<Option<Vec<(String, String)

Ok(Some(res))
}

fn host(url: &str) -> Option<String> {
url::Url::parse(url)
.ok()
.and_then(|u| u.host().map(|h| h.to_string()))
}

0 comments on commit ca555e1

Please sign in to comment.