Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions .changelog/1757207291.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
applies_to: [server]
authors: [drganjoo]
references: []
breaking: false
new_feature: false
bug_fix: true
---
Fixed URI path matching for H2 protocol in the ALB health check layer to ensure explicit path comparison.

2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-http-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-smithy-http-server"
version = "0.65.5"
version = "0.65.6"
authors = ["Smithy Rust Server <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ where
}

fn call(&mut self, req: Request<Body>) -> Self::Future {
if req.uri() == self.layer.health_check_uri.as_ref() {
if req.uri().path() == self.layer.health_check_uri.as_ref() {
let clone = self.layer.health_check_handler.clone();
let service = std::mem::replace(&mut self.layer.health_check_handler, clone);
let handler_future = service.oneshot(req);
Expand Down Expand Up @@ -179,3 +179,39 @@ where
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use http::Uri;
use tower::{service_fn, ServiceExt};

#[tokio::test]
async fn health_check_matches_path_when_uri_contains_scheme_authority_and_path() {
let uri: Uri = "https://example.com/ping".parse().unwrap();
ensure_health_check_path_matches(uri, "/ping".to_string()).await;
}

#[tokio::test]
async fn health_check_matches_path_when_uri_contains_only_path() {
let uri: Uri = "/ping".parse().unwrap();
ensure_health_check_path_matches(uri, "/ping".to_string()).await;
}

async fn ensure_health_check_path_matches(uri: Uri, health_check_path: String) {
let layer = AlbHealthCheckLayer::from_handler(health_check_path, |_req| async { StatusCode::OK });
let inner_service = service_fn(|_req| async {
Ok::<_, std::convert::Infallible>(
Response::builder()
.status(StatusCode::IM_A_TEAPOT)
.body(crate::body::empty())
.expect("infallible"),
)
});

let service = layer.layer(inner_service);
let request = Request::builder().uri(uri).body(Body::empty()).unwrap();
let response = service.oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
}
}
Loading