[FE] [HttpServer] Config netty param in HttpServer (#4225)

Now, if the length of URL is longer than 4096 bytes, netty will refuse.
The case can be reproduced by constructing a very long URL(longer than 4096bytes)

Add 2 http server params:
1. http_max_line_length
2. http_max_header_size
This commit is contained in:
Lijia Liu
2020-08-01 17:59:01 +08:00
committed by GitHub
parent 116d7ffa3c
commit bdaef84a10
5 changed files with 56 additions and 3 deletions

View File

@ -333,6 +333,16 @@ This variable is a dynamic configuration, and users can modify the configuration
### `http_port`
HTTP bind port. Defaults to 8030.
### `http_max_line_length`
The max length of an HTTP URL. The unit of this configuration is BYTE. Defaults to 4096.
### `http_max_header_size`
The max size of allowed HTTP headers. The unit of this configuration is BYTE. Defaults to 8192.
### `ignore_meta_check`
### `init_connect`

View File

@ -331,6 +331,16 @@ FE 的配置项有两种方式进行配置:
### `http_port`
HTTP服务监听的端口号,默认为8030
### `http_max_line_length`
HTTP服务允许接收请求的URL的最大长度,单位为比特,默认是4096
### `http_max_header_size`
HTTP服务允许接收请求的Header的最大长度,单位为比特,默认是8192
### `ignore_meta_check`
### `init_connect`

View File

@ -111,7 +111,12 @@ public class PaloFe {
// 3. HttpServer for HTTP Server
QeService qeService = new QeService(Config.query_port, Config.mysql_service_nio_enabled, ExecuteEnv.getInstance().getScheduler());
FeServer feServer = new FeServer(Config.rpc_port);
HttpServer httpServer = new HttpServer(Config.http_port);
HttpServer httpServer = new HttpServer(
Config.http_port,
Config.http_max_line_length,
Config.http_max_header_size,
Config.http_max_chunk_size
);
httpServer.setup();
feServer.start();

View File

@ -18,6 +18,7 @@
package org.apache.doris.common;
import org.apache.doris.PaloFe;
import org.apache.doris.http.HttpServer;
public class Config extends ConfigBase {
@ -284,6 +285,15 @@ public class Config extends ConfigBase {
*/
@ConfField public static int http_port = 8030;
/*
* Netty http param
*/
@ConfField public static int http_max_line_length = HttpServer.DEFAULT_MAX_LINE_LENGTH;
@ConfField public static int http_max_header_size = HttpServer.DEFAULT_MAX_HEADER_SIZE;
@ConfField public static int http_max_chunk_size = HttpServer.DEFAULT_MAX_CHUNK_SIZE;
/**
* The backlog_num for netty http server
* When you enlarge this backlog_num, you should ensure it's value larger than

View File

@ -94,7 +94,18 @@ import io.netty.handler.stream.ChunkedWriteHandler;
public class HttpServer {
private static final Logger LOG = LogManager.getLogger(HttpServer.class);
private int port;
/**
* The default netty param, witch is the same as `HttpServerCodec`.
*/
public static final int DEFAULT_MAX_LINE_LENGTH = 4096;
public static final int DEFAULT_MAX_HEADER_SIZE = 8192;
public static final int DEFAULT_MAX_CHUNK_SIZE = 8192;
private final int port;
private final int maxInitialLineLength;
private final int maxHeaderSize;
private final int maxChunkSize;
private ActionController controller;
private Thread serverThread;
@ -102,7 +113,14 @@ public class HttpServer {
private AtomicBoolean isStarted = new AtomicBoolean(false);
public HttpServer(int port) {
this(port, DEFAULT_MAX_LINE_LENGTH, DEFAULT_MAX_HEADER_SIZE, DEFAULT_MAX_CHUNK_SIZE);
}
public HttpServer(int port, int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) {
this.port = port;
this.maxInitialLineLength = maxInitialLineLength;
this.maxHeaderSize = maxHeaderSize;
this.maxChunkSize = maxChunkSize;
controller = new ActionController();
}
@ -188,7 +206,7 @@ public class HttpServer {
protected class PaloHttpServerInitializer extends ChannelInitializer<SocketChannel> {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new HttpServerCodec());
ch.pipeline().addLast(new HttpServerCodec(maxInitialLineLength, maxHeaderSize, maxChunkSize));
ch.pipeline().addLast(new DorisHttpPostObjectAggregator(100 * 65536));
ch.pipeline().addLast(new ChunkedWriteHandler());
ch.pipeline().addLast(new HttpServerHandler(controller));