tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier>
Subject Re: How to prevent/abort the processing of the multipart request body?
Date Mon, 14 Mar 2011 11:01:35 GMT
Attila Király wrote:
> Hi,
> I have the following situation: a html page contains a multipart form with a
> file typed input field. User submits the form. I can decide not to parse the
> multipart body at all on the server side in a filter (because the request is
> too large based on the content-length header sent by the UA). I would like
> to communicate this to the UA as fast as possible (possibly before the UA
> starts pumping the file into the TCP). However the file is still sent by the
> UA and it is probably still read (and skipped) by tomcat. Can this data
> transfer be prevented? I tried to do something like this (forcing the close
> of the connection):
> public void doFilter(ServletRequest request, ServletResponse response,
>     FilterChain chain) throws IOException, ServletException {
>   HttpServletResponse httpResponse = (HttpServletResponse) response;
>   httpResponse.setHeader("Connection", "close");
>   httpResponse.sendError(413);
>   response.flushBuffer();
>   request.getInputStream().close();
>   response.getOutputStream().close();
> }
> But it was no use. Preventing the upload would save time for the user,
> bandwidth for the network and CPU cycles for the server. Any ideas how to do
> it (or why it can't be done)?

Maybe have a look here :

attribute maxPostSize

About the code above : (guessing) it probably does not help, because Tomcat is buffering 
the POST somewhere, even before passing the request to the webapp.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message