Skip to content

Commit 0efa7b5

Browse files
Feat: Add configurable JSON-RPC request and response body size limits
1 parent 47d05a1 commit 0efa7b5

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎docs/guide/config/server.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ ws_listener = "0.0.0.0:3000"
77
# JSON-RPC 最大连接数,默认 100
88
jsonrpc_max_connections = 100
99

10+
# JSON-RPC 最大请求体大小,单位字节,默认 10485760(10MB)
11+
# max_request_body_size = 10485760
12+
13+
# JSON-RPC 最大响应体大小,单位字节,默认 10485760(10MB)
14+
# max_response_body_size = 10485760
15+
1016
# 是否启用 Unix Socket(仅非 Windows 平台)
1117
# 启用后会额外监听 unix_socket_path 对应的 Axum 主路由
1218
enable_unix_socket = false

‎nodeget-lib/src/config/server.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ pub struct ServerConfig {
3030

3131
// 监控数据缓冲写入配置(可选)
3232
pub monitoring_buffer: Option<MonitoringBufferConfig>,
33+
34+
// JSON-RPC 最大请求体大小(字节),默认 10485760(10MB)
35+
pub max_request_body_size: Option<u32>,
36+
37+
// JSON-RPC 最大响应体大小(字节),默认 10485760(10MB)
38+
pub max_response_body_size: Option<u32>,
3339
}
3440

3541
/// 监控数据缓冲写入配置

‎server/config.toml.example‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ ws_listener = "0.0.0.0:3000"
44
# JSON-RPC 最大连接数,默认 100
55
jsonrpc_max_connections = 100
66

7+
# JSON-RPC 最大请求体大小,单位字节,默认 10485760(10MB)
8+
# max_request_body_size = 10485760
9+
10+
# JSON-RPC 最大响应体大小,单位字节,默认 10485760(10MB)
11+
# max_response_body_size = 10485760
12+
713
# 是否启用 Unix Socket(仅非 Windows 平台)
814
# 启用后会额外监听 unix_socket_path 对应的 Axum 主路由
915
enable_unix_socket = false

‎server/src/subcommands/serve.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ pub async fn run(config: &nodeget_lib::config::server::ServerConfig) {
6060
.set_config(
6161
jsonrpsee::server::ServerConfig::builder()
6262
.max_connections(config.jsonrpc_max_connections.unwrap_or(100))
63-
.max_response_body_size(u32::MAX)
64-
.max_request_body_size(u32::MAX)
63+
.max_response_body_size(config.max_response_body_size.unwrap_or(10 * 1024 * 1024))
64+
.max_request_body_size(config.max_request_body_size.unwrap_or(10 * 1024 * 1024))
6565
.build(),
6666
)
6767
.to_service_builder()

0 commit comments

Comments
 (0)