After perusing the official documentation of Tomcat, I diligently delved into the significance of the "maxSwallow" parameter. Alas, despite configuring this particular parameter, its intended effect eluded me. In a quest to resolve this perplexity, I delved into an issue previously addressed by fellow developers, yet implementing the suggested approach you mentioned proved ineffective. Version information: Spring boot 2.4.0 Controller Demo:
@RestController
public class TextBodyController {
private final static Logger logging = Logger.getLogger(TextBodyController.class.getName());
@PostMapping("/text")
public void handleText() {
logging.log(Level.INFO, "Request successful.");
}
}
application.yaml
server:
tomcat:
max-swallow-size: 1B
curl request
curl -X POST -F "data=@test.txt" http://172.21.32.45:8080/text
test.txt has been uploaded.
Comment From: bclozel
From the Tomcat documentation:
The maximum number of request body bytes (excluding transfer encoding overhead) that will be swallowed by Tomcat for an aborted upload. An aborted upload is when Tomcat knows that the request body is going to be ignored but the client still sends it. If Tomcat does not swallow the body the client is unlikely to see the response. If not specified the default of 2097152 (2 megabytes) will be used. A value of less than zero indicates that no limit should be enforced.
To see this option in action, you would need to:
- have a client that sends a request body
- the server not reading it at all and sending immediately a response, like an error
- if the body exceeds the configured size, Tomcat will not attempt to consume those bytes and will still send the response. As afar as I understand this could mean that the client won't see the response or that the client could consider the connection as invalid and close it.
Comment From: Zengwenliang0416
Thanks for your patience, the test demo written under your guidance does prove that the parameter has taken effect in debug mode. The exception of this parameter is different from the level of max-http-form-post-size in tomcat, and it does not output this exception but EOFException in the logs, may I ask your team whether you need to adjust the level of the exception to inform the developers that the current parameter is too small.
Comment From: Zengwenliang0416