title: Is it possible to intercept a request before the request body will be received
body: <p>The original problem: limit multipart file upload size by e.g. <code>10mb</code> on the level of Tomcat.</p>
  
  <p>My current solution (based on Spring Boot's <code>StandardMultipartHttpServletRequest</code>) checks internally the <code>Content-Length</code> request header first. Sounds fine so far...</p>
  
  <p>But I see that for huge files the notable delay (which corresponds to the file size) appears before this check comes in action and even before any servlet filter logic. In fact, I get this delay before (or somewhere inside) <code>org.apache.tomcat.util.net.NioEndpoint</code>, which is the second call in the stacktrace (the first one is <code>Thread</code>).</p>
  
  <p>Looks like tomcat loads the complete request body on the low level before any application logic is applied.</p>
  
  <p>By contrast, when I wrap Tomcat in Nginx as a reverse proxy and limit file size in Nginx (which also checks the header only), it breaks upload instantly.</p>
  
  <p>The question: is it technically possible to perform any logic in Tomcat before request body upload is done? In particular, for limiting file size?</p>