MaxRequestBodySize on RouteConfig class has no effect
nazirj-absa opened this issue · comments
Describe the bug
The value is set in code. The RateLimiterPolicy works brilliantly.
However, we would like to limit the body request on certain endpoints.
MaxRequestBodySize - is different per route.
However, it has no effect.
Setting the value to a modest 53 bytes on a limit of 50 bytes has no effect.
RouteConfig routeItem = new RouteConfig() { RouteId = $"route-{endpoint.Name}-{Random.Shared.Next()}", ClusterId = endpoint.ClusterId, Match = new RouteMatch { Path = $"/{pathPrefix}{endpoint.MatchPath}" }, RateLimiterPolicy = endpoint.RateLimiterPolicy, MaxRequestBodySize = endpoint.MaxRequestBodySize, Transforms = new List<Dictionary<string, string>>() { new Dictionary<string, string> { { "PathSet", endpoint.TransformPath } } }, AuthorizationPolicy = endpoint.AuthorizationPolicy };
To Reproduce
Use postman to perform a post or put with the json payload of:
{"val":"test","val1":"test","val2":"test11111111111111111111111111111111111111111111111111111111111"}
i.e. 101 bytes.
If the route has MaxRequestBodySize of 50 bytes - the request still returns with a 200 status.
[HttpPut("UpdateItem")]
public ActionResult UpdateItem([FromBody] JsonElement body)
{
return Ok($"updated - {body.ToString()}");
}
[HttpPost("CreateItem")]
public ActionResult CreateItem([FromBody] JsonElement body)
{
return Ok($"created - {body.ToString()}");
}
Further technical details
- Include the version of the packages you are using
- The platform is Windows.
- Yarp version 2.1.0