tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Attila Király <>
Subject How to prevent/abort the processing of the multipart request body?
Date Mon, 14 Mar 2011 08:22:02 GMT

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");
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)?

Attila Király

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message