Skip to content

Commit 12bd774

Browse files
author
Fahad Zubair
committed
For h2, uri path should be explicitly matched
1 parent 5550f44 commit 12bd774

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

rust-runtime/aws-smithy-http-server/src/layer/alb_health_check.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ where
108108
}
109109

110110
fn call(&mut self, req: Request<Body>) -> Self::Future {
111-
if req.uri() == self.layer.health_check_uri.as_ref() {
111+
if req.uri().path() == self.layer.health_check_uri.as_ref() {
112112
let clone = self.layer.health_check_handler.clone();
113113
let service = std::mem::replace(&mut self.layer.health_check_handler, clone);
114114
let handler_future = service.oneshot(req);
@@ -179,3 +179,32 @@ where
179179
}
180180
}
181181
}
182+
183+
#[cfg(test)]
184+
mod tests {
185+
use super::*;
186+
use http::Uri;
187+
use tower::{service_fn, ServiceExt};
188+
189+
#[tokio::test]
190+
async fn health_check_matches_path_with_scheme_and_authority() {
191+
let layer = AlbHealthCheckLayer::from_handler("/ping", |_req| async { StatusCode::OK });
192+
193+
let inner_service = service_fn(|_req| async {
194+
Ok::<_, std::convert::Infallible>(
195+
Response::builder()
196+
.status(StatusCode::IM_A_TEAPOT)
197+
.body(crate::body::empty())
198+
.expect("infallible"),
199+
)
200+
});
201+
202+
let service = layer.layer(inner_service);
203+
204+
let uri: Uri = "https://example.com/ping".parse().unwrap();
205+
let request = Request::builder().uri(uri).body(Body::empty()).unwrap();
206+
207+
let response = service.oneshot(request).await.unwrap();
208+
assert_eq!(response.status(), StatusCode::OK);
209+
}
210+
}

0 commit comments

Comments
 (0)