Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetty HTTP 413 Header Full error - Java/Scala

I am using Jetty 7.6 with Scalatra web framework. In some of the requests, I need to send a large text as response body to the client, I use HttpServletResponse.getWriter() to write response.

I noticed that on client side I receive 413 Header Full error. Apparently one solution to this problem in Jetty is to increase jetty's header-buffer-size value.

I would like to know what does HttpServletResponse.getWriter() has to do with the size of the header of request ?! As I understand HttpServletResponse.getWriter() writes into response body rather than response header.

I appreciate if someone could explain this issue.

like image 467
Ali Salehi Avatar asked Aug 11 '12 12:08

Ali Salehi


1 Answers

Unfortunately, this is not only headers that matters (like joakime thougth). Jetty has a buffer for headers and a buffer for request.

  • If the full request (http data stream) fits in the hearder's buffer no problem.
  • If it exceeds the header's buffer, the request buffer will be user.
  • If it exceeds the request buffer then you got a standard Http response with status 413.

There is the same thing (buffer) for the answer but hopefully Http is designed to send "chunked" response.

I'm facing the same problem with an upload.

What I've found is that you can set the size of those buffers. See: http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/server/nio/SelectChannelConnector.html

http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/server/nio/AbstractNIOConnector.html

http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/server/AbstractConnector.html#setRequestHeaderSize(int)

You can use jetty.xml file to do it :

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"     "http://jetty.mortbay.org/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
 <Call name="addConnector">
  <Arg>
   <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
    <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
    <Set name="requestHeaderSize">8192</Set>
   </New>
  </Arg>
 </Call>
</Configure>
like image 184
Sylvain Avatar answered Oct 01 '22 11:10

Sylvain