Add option for user to set max size limit for RPC requests (#9010)
* Add option for user to set max size limit for RPC requests as requested in #8961. * Add max_payload to tests. * Change name for max payload option and change value from NUM to MB. * Fix broken test. * Fix incorrect indentation.
This commit is contained in:
parent
34bf2452c3
commit
67721f3413
@ -482,6 +482,10 @@ usage! {
|
||||
"--jsonrpc-server-threads=[NUM]",
|
||||
"Enables multiple threads handling incoming connections for HTTP JSON-RPC server.",
|
||||
|
||||
ARG arg_jsonrpc_max_payload: (Option<usize>) = None, or |c: &Config| c.rpc.as_ref()?.max_payload,
|
||||
"--jsonrpc-max-payload=[MB]",
|
||||
"Specify maximum size for RPC requests in megabytes.",
|
||||
|
||||
["API and Console Options – WebSockets"]
|
||||
FLAG flag_no_ws: (bool) = false, or |c: &Config| c.websockets.as_ref()?.disable.clone(),
|
||||
"--no-ws",
|
||||
@ -1165,6 +1169,7 @@ struct Rpc {
|
||||
hosts: Option<Vec<String>>,
|
||||
server_threads: Option<usize>,
|
||||
processing_threads: Option<usize>,
|
||||
max_payload: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
@ -1613,6 +1618,7 @@ mod tests {
|
||||
arg_jsonrpc_hosts: "none".into(),
|
||||
arg_jsonrpc_server_threads: None,
|
||||
arg_jsonrpc_threads: 4,
|
||||
arg_jsonrpc_max_payload: None,
|
||||
|
||||
// WS
|
||||
flag_no_ws: false,
|
||||
@ -1880,6 +1886,7 @@ mod tests {
|
||||
hosts: None,
|
||||
server_threads: None,
|
||||
processing_threads: None,
|
||||
max_payload: None,
|
||||
}),
|
||||
ipc: Some(Ipc {
|
||||
disable: None,
|
||||
|
@ -879,6 +879,10 @@ impl Configuration {
|
||||
_ => 1,
|
||||
},
|
||||
processing_threads: self.args.arg_jsonrpc_threads,
|
||||
max_payload: match self.args.arg_jsonrpc_max_payload {
|
||||
Some(max) if max > 0 => max as usize,
|
||||
_ => 5usize,
|
||||
},
|
||||
};
|
||||
|
||||
Ok(conf)
|
||||
|
@ -45,6 +45,7 @@ pub struct HttpConfiguration {
|
||||
pub hosts: Option<Vec<String>>,
|
||||
pub server_threads: usize,
|
||||
pub processing_threads: usize,
|
||||
pub max_payload: usize,
|
||||
}
|
||||
|
||||
impl HttpConfiguration {
|
||||
@ -64,6 +65,7 @@ impl Default for HttpConfiguration {
|
||||
hosts: Some(vec![]),
|
||||
server_threads: 1,
|
||||
processing_threads: 4,
|
||||
max_payload: 5,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -232,6 +234,7 @@ pub fn new_http<D: rpc_apis::Dependencies>(
|
||||
rpc::RpcExtractor,
|
||||
middleware,
|
||||
conf.server_threads,
|
||||
conf.max_payload,
|
||||
);
|
||||
|
||||
match start_result {
|
||||
|
@ -140,6 +140,7 @@ pub fn start_http<M, S, H, T, R>(
|
||||
extractor: T,
|
||||
middleware: Option<R>,
|
||||
threads: usize,
|
||||
max_payload: usize,
|
||||
) -> ::std::io::Result<HttpServer> where
|
||||
M: jsonrpc_core::Metadata,
|
||||
S: jsonrpc_core::Middleware<M>,
|
||||
@ -152,7 +153,8 @@ pub fn start_http<M, S, H, T, R>(
|
||||
.threads(threads)
|
||||
.event_loop_remote(remote)
|
||||
.cors(cors_domains.into())
|
||||
.allowed_hosts(allowed_hosts.into());
|
||||
.allowed_hosts(allowed_hosts.into())
|
||||
.max_request_body_size(max_payload * 1024 * 1024);
|
||||
|
||||
if let Some(dapps) = middleware {
|
||||
builder = builder.request_middleware(dapps)
|
||||
|
@ -40,6 +40,7 @@ fn serve(handler: Option<MetaIoHandler<Metadata>>) -> Server<HttpServer> {
|
||||
}
|
||||
}),
|
||||
1,
|
||||
5,
|
||||
).unwrap())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user