Skip to content

Commit

Permalink
factors: Invert if statement for consistency
Browse files Browse the repository at this point in the history
Signed-off-by: Lann Martin <[email protected]>
  • Loading branch information
lann committed Aug 21, 2024
1 parent 951760c commit e9da68a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions crates/factor-outbound-http/src/spin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ impl spin_http::Host for crate::InstanceState {
let uri = req.uri;
tracing::trace!("Sending outbound HTTP to {uri:?}");

let abs_url = if uri.starts_with('/') {
let abs_url = if !uri.starts_with('/') {
// Absolute URI
let is_allowed = self
.allowed_hosts
.check_url(&uri, "https")
.await
.unwrap_or(false);
if !is_allowed {
return Err(HttpError::DestinationNotAllowed);
}
uri
} else {
// Relative URI ("self" request)
let is_allowed = self
.allowed_hosts
Expand All @@ -37,17 +48,6 @@ impl spin_http::Host for crate::InstanceState {
return Err(HttpError::InvalidUrl);
};
format!("{origin}{uri}")
} else {
// Absolute URI
let is_allowed = self
.allowed_hosts
.check_url(&uri, "https")
.await
.unwrap_or(false);
if !is_allowed {
return Err(HttpError::DestinationNotAllowed);
}
uri
};
let req_url = reqwest::Url::parse(&abs_url).map_err(|_| HttpError::InvalidUrl)?;

Expand Down

0 comments on commit e9da68a

Please sign in to comment.