Skip to content

Commit

Permalink
Merge pull request #261 from /issues/257-qrest-large-header
Browse files Browse the repository at this point in the history
Add ability to configure max header size
  • Loading branch information
ar authored Aug 16, 2022
2 parents b9ce14a + a3303be commit acbbf89
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions modules/qrest/src/main/java/org/jpos/qrest/RestServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.QueryStringDecoder;
import io.netty.handler.codec.http.*;
import io.netty.handler.ssl.SslHandler;
import io.netty.handler.timeout.IdleStateHandler;
import org.jdom2.Element;
Expand All @@ -52,9 +49,7 @@

import javax.net.ssl.*;

import static org.jpos.qrest.Constants.PATHPARAMS;
import static org.jpos.qrest.Constants.QUERYPARAMS;
import static org.jpos.qrest.Constants.REQUEST;
import static io.netty.handler.codec.http.HttpObjectDecoder.*;

public class RestServer extends QBeanSupport implements Runnable, XmlConfigurable {
private ServerBootstrap serverBootstrap;
Expand All @@ -76,6 +71,13 @@ public class RestServer extends QBeanSupport implements Runnable, XmlConfigurabl
private String queue;
private Map<String,List<Route<String>>> routes = new HashMap<>();

private int maxHeaderSize;
private int maxContentLength;
private int maxInitialLineLength;
private int maxChunkSize;
private boolean validateHeaders;

public static final int DEFAULT_MAX_CONTENT_LENGTH = 512*1024;

@Override
protected void initService() throws GeneralSecurityException, IOException {
Expand All @@ -95,8 +97,8 @@ public void initChannel(SocketChannel ch) throws Exception {
if (enableTLS) {
ch.pipeline().addLast(new SslHandler(getSSLEngine(sslContext), true));
}
ch.pipeline().addLast(new HttpServerCodec()) ;
ch.pipeline().addLast(new HttpObjectAggregator(512*1024));
ch.pipeline().addLast(new HttpServerCodec(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders));
ch.pipeline().addLast(new HttpObjectAggregator(maxContentLength));
ch.pipeline().addLast(new RestSession(RestServer.this));
}
})
Expand Down Expand Up @@ -173,6 +175,12 @@ public void setConfiguration (Configuration cfg) throws ConfigurationException {
enabledCipherSuites = cfg.getAll("enabled-cipher");
enabledProtocols = cfg.getAll("enable-protocol");
queue = cfg.get("queue");

maxHeaderSize = cfg.getInt("maxHeaderSize", DEFAULT_MAX_HEADER_SIZE);
maxContentLength = cfg.getInt("maxContentLength", DEFAULT_MAX_CONTENT_LENGTH);
maxInitialLineLength = cfg.getInt("maxInitialLineLength", DEFAULT_MAX_INITIAL_LINE_LENGTH);
maxChunkSize = cfg.getInt("maxChunkSize", DEFAULT_MAX_CHUNK_SIZE);
validateHeaders = cfg.getBoolean("validateHeaders", DEFAULT_CHUNKED_SUPPORTED);
}

@Override
Expand Down

0 comments on commit acbbf89

Please # to comment.