Skip to content

Commit

Permalink
Merge pull request #1008 from gurkancakir/master
Browse files Browse the repository at this point in the history
io.netty.handler.codec.http.TooLongHttpLineException: An HTTP line is larger than 4096 bytes.
  • Loading branch information
mrniko authored Oct 31, 2024
2 parents c4ca71e + c71f3aa commit 5cce222
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/main/java/com/corundumstudio/socketio/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.corundumstudio.socketio.protocol.JsonSupport;
import com.corundumstudio.socketio.store.MemoryStoreFactory;
import com.corundumstudio.socketio.store.StoreFactory;
import io.netty.handler.codec.http.HttpDecoderConfig;

import javax.net.ssl.KeyManagerFactory;

Expand Down Expand Up @@ -92,6 +93,8 @@ public class Configuration {

private boolean needClientAuth = false;

private HttpRequestDecoderConfiguration httpRequestDecoderConfiguration = new HttpRequestDecoderConfiguration();

public Configuration() {
}

Expand Down Expand Up @@ -161,6 +164,7 @@ public Configuration() {
setWebsocketCompression(conf.isWebsocketCompression());
setRandomSession(conf.randomSession);
setNeedClientAuth(conf.isNeedClientAuth());
setHttpRequestDecoderConfiguration(conf.getHttpRequestDecoderConfiguration());
}

public JsonSupport getJsonSupport() {
Expand Down Expand Up @@ -618,4 +622,19 @@ public void setNeedClientAuth(boolean needClientAuth) {
public boolean isNeedClientAuth() {
return needClientAuth;
}

public HttpRequestDecoderConfiguration getHttpRequestDecoderConfiguration() {
return httpRequestDecoderConfiguration;
}

public void setHttpRequestDecoderConfiguration(HttpRequestDecoderConfiguration httpRequestDecoderConfiguration) {
this.httpRequestDecoderConfiguration = httpRequestDecoderConfiguration;
}

public HttpDecoderConfig getHttpDecoderConfig() {
return new HttpDecoderConfig()
.setMaxInitialLineLength(httpRequestDecoderConfiguration.getMaxInitialLineLength())
.setMaxHeaderSize(httpRequestDecoderConfiguration.getMaxHeaderSize())
.setMaxChunkSize(httpRequestDecoderConfiguration.getMaxChunkSize());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.corundumstudio.socketio;

public class HttpRequestDecoderConfiguration {

private int maxInitialLineLength;
private int maxHeaderSize;
private int maxChunkSize;

public HttpRequestDecoderConfiguration(int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) {
this.maxInitialLineLength = maxInitialLineLength;
this.maxHeaderSize = maxHeaderSize;
this.maxChunkSize = maxChunkSize;
}

public HttpRequestDecoderConfiguration() {
this(4096, 8192, 8192);
}

public int getMaxInitialLineLength() {
return maxInitialLineLength;
}

public void setMaxInitialLineLength(int maxInitialLineLength) {
this.maxInitialLineLength = maxInitialLineLength;
}

public int getMaxHeaderSize() {
return maxHeaderSize;
}

public void setMaxHeaderSize(int maxHeaderSize) {
this.maxHeaderSize = maxHeaderSize;
}

public int getMaxChunkSize() {
return maxChunkSize;
}

public void setMaxChunkSize(int maxChunkSize) {
this.maxChunkSize = maxChunkSize;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected void addSslHandler(ChannelPipeline pipeline) {
* @param pipeline - channel pipeline
*/
protected void addSocketioHandlers(ChannelPipeline pipeline) {
pipeline.addLast(HTTP_REQUEST_DECODER, new HttpRequestDecoder());
pipeline.addLast(HTTP_REQUEST_DECODER, new HttpRequestDecoder(configuration.getHttpDecoderConfig()));
pipeline.addLast(HTTP_AGGREGATOR, new HttpObjectAggregator(configuration.getMaxHttpContentLength()) {
@Override
protected Object newContinueResponse(HttpMessage start, int maxContentLength,
Expand Down

0 comments on commit 5cce222

Please sign in to comment.