javajettyembedded-jettyjetty-12

How do you set in Jetty 12 a max request size programmatically


By default jetty 12 automatically drops the connection if request size is larger than ~ 1MB. Is there a way to set a larger request size?

I've tried

        HttpConfiguration httpConfig = new HttpConfiguration();
        httpConfig.setRequestHeaderSize(100 * 1024 * 1024); // 100MB

but is not working. I found that on older version you can set this.server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", 200 * 1024 * 1024); but this is not working as well.

I'm interesting in doing this programmatically since I'm embedding Jetty in a larger app.

I'm using Jetty 12.0.10 with java 21

To increase the request size so the server doesn't drop the connection


Solution

  • You are mixing 3 different concepts, and your question is starting to not make sense.

    There is no such thing as a limit on Request Size. That doesn't exist, and Jetty is perfectly capable of receiving a request with a body content well past the exabyte size on any machine configuration that Jetty runs on.

    Request Headers Size - that's controlled by the HttpConfiguration as you have discovered, leave this alone, any size larger than default will fail on a variety of hardware and browser implementations. (200MB in request headers is absolutely insane, you need that, then you are abusing the HTTP protocol and you should look into proper use of HTTP asap!)

    Max Form Content Size - this ONLY applies to blocking form access (does not apply when using Async form APIs). This also is limited to HTTP (PUT or POST) requests that have a body content that is declared as Content-Type of either application/x-www-form-urlencoded or multipart/form-data. Any other Content-Type or HTTP method and "Max Form Content Size" does not apply.

    With Jetty 12.0.x you have the following choices for controlling Max Form Content Size ...

    These configurations cannot be set via a Attribute, Server or otherwise.