Skip to content

Commit

Permalink
jetty: Configuring jetty max header size
Browse files Browse the repository at this point in the history
- fix #2909
- allow to configure custom jetty options

```java
{
   use(
     new JettyServer()
         .configure(http -> {
             http.setRequestHeaderSize(16 * 1024);
         })
   )
}
```
  • Loading branch information
jknack committed May 13, 2023
1 parent e564d66 commit 06b000e
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class JettyServer extends io.jooby.Server.Base {

private ServerOptions options = new ServerOptions().setServer("jetty").setWorkerThreads(THREADS);

private Consumer<HttpConfiguration> httpConfigurer;

public JettyServer(@NonNull ThreadPool threadPool) {
this.threadPool = threadPool;
}
Expand All @@ -83,6 +85,17 @@ public String getName() {
return "jetty";
}

/**
* Applies custom configuration. This applies to HTTP and HTTPS (when enable).
*
* @param configurer Configurer.
* @return This server.
*/
public JettyServer configure(Consumer<HttpConfiguration> configurer) {
this.httpConfigurer = configurer;
return this;
}

@NonNull @Override
public io.jooby.Server start(Jooby application) {
try {
Expand All @@ -109,7 +122,6 @@ public io.jooby.Server start(Jooby application) {
options.isHttp2() == Boolean.TRUE ? new JettyHttp2Configurer() : null;

HttpConfiguration httpConf = new HttpConfiguration();
// TODO: we might need to remove legacy with default
httpConf.setUriCompliance(UriCompliance.LEGACY);
httpConf.setOutputBufferSize(options.getBufferSize());
httpConf.setOutputAggregationSize(options.getBufferSize());
Expand All @@ -118,6 +130,10 @@ public io.jooby.Server start(Jooby application) {
httpConf.setSendServerVersion(false);
httpConf.setMultiPartFormDataCompliance(MultiPartFormDataCompliance.RFC7578);

if (httpConfigurer != null) {
httpConfigurer.accept(httpConf);
}

List<ConnectionFactory> connectionFactories = new ArrayList<>();
connectionFactories.add(new HttpConnectionFactory(httpConf));
if (http2 != null) {
Expand Down

0 comments on commit 06b000e

Please sign in to comment.