Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.netty.handler.codec.http.TooLongHttpLineException: An HTTP line is larger than 4096 bytes. #1008

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading