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

Thanks,
Attila Király

Reply via email to