fix(http): separate transport and protocol limits

This commit is contained in:
2026-10-02 02:50:56 +09:00
parent 65c51006ad
commit df006ee706
12 changed files with 643 additions and 336 deletions
+42 -2
View File
@@ -61,7 +61,10 @@ fn inbound_http_metadata_enforces_post_route_and_json() {
.header("content-type", "application/json")
.body(Vec::<u8>::new())
.unwrap();
assert!(validate_http_request(&endpoint, Route::Observe, &wrong_method).is_err());
let error = validate_http_request(&endpoint, Route::Observe, &wrong_method).unwrap_err();
assert!(matches!(&error, RequestMetadataError::MethodNotAllowed));
assert_eq!(error.status(), StatusCode::METHOD_NOT_ALLOWED);
assert_eq!(error.allow(), Some("POST"));
let wrong_route = Request::builder()
.method(Method::POST)
@@ -69,7 +72,21 @@ fn inbound_http_metadata_enforces_post_route_and_json() {
.header("content-type", "application/json")
.body(Vec::<u8>::new())
.unwrap();
assert!(validate_http_request(&endpoint, Route::Observe, &wrong_route).is_err());
let error = validate_http_request(&endpoint, Route::Observe, &wrong_route).unwrap_err();
assert!(matches!(&error, RequestMetadataError::NotFound));
assert_eq!(error.status(), StatusCode::NOT_FOUND);
assert_eq!(error.allow(), None);
let query_and_wrong_method = Request::builder()
.method(Method::GET)
.uri("/wip/v1/observe?unexpected=true")
.header("content-type", "application/json")
.body(Vec::<u8>::new())
.unwrap();
assert!(matches!(
validate_http_request(&endpoint, Route::Observe, &query_and_wrong_method).unwrap_err(),
RequestMetadataError::NotFound
));
for accept in [
"text/plain, */*;q=1, application/json;q=0",
@@ -114,6 +131,29 @@ fn inbound_http_metadata_enforces_post_route_and_json() {
validate_http_request(&endpoint, Route::Observe, &unsupported_media_type).unwrap_err();
assert!(matches!(&error, RequestMetadataError::UnsupportedMediaType));
assert_eq!(error.status(), StatusCode::UNSUPPORTED_MEDIA_TYPE);
for coding in ["gzip", "identity, gzip"] {
let unsupported_coding = Request::builder()
.method(Method::POST)
.uri("/wip/v1/observe")
.header("content-type", "application/json")
.header("content-encoding", coding)
.body(Vec::<u8>::new())
.unwrap();
let error =
validate_http_request(&endpoint, Route::Observe, &unsupported_coding).unwrap_err();
assert!(matches!(&error, RequestMetadataError::UnsupportedMediaType));
assert_eq!(error.status(), StatusCode::UNSUPPORTED_MEDIA_TYPE);
}
let identity_coding = Request::builder()
.method(Method::POST)
.uri("/wip/v1/observe")
.header("content-type", "application/json")
.header("content-encoding", "identity")
.body(Vec::<u8>::new())
.unwrap();
assert!(validate_http_request(&endpoint, Route::Observe, &identity_coding).is_ok());
}
#[test]