I have the most basic spring-boot-starter web project with a single POST endpoint which prints the size of the request body
I want to configure spring boot so that it will not accept uploads of more than 32KB.
Is there anyway to achieve this?, i.e. to have spring boot mvc reject a request that exceeds the configured max upload size?
I am using spring boot version 2.1.5.RELEASE.
I have tried
server.tomcat.max-http-post-size=1KB
server.tomcat.max-swallow-size=1KB
spring.servlet.multipart.max-file-size=1KB
spring.servlet.multipart.max-request-size=1KB
This is my one and only endpoint:
@RequestMapping(value = "", method = RequestMethod.POST)
public ResponseEntity<String> pong(@RequestBody String body) {
return new ResponseEntity<>("FINISHED: " + body.length(), HttpStatus.OK);
}
No matter which coniguration I use I can execute
curl -sS -X POST -H "Content-type: application/text" http://localhost:8080/ --data-binary @./file2.txt
where file2.txt is a 900Mb file and this results in
{"timestamp":"2019-06-18T17:52:03.244+0000","status":500,"error":"Internal Server Error","message":"Java heap space","path":"/"}
I would prefer some kind of exception that indicates this amount of data exceeds the configured limit.
Thank you.