Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Add option for user to set max size limit for RPC requests #9010

Merged
merged 5 commits into from
Jul 2, 2018
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
7 changes: 7 additions & 0 deletions parity/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1880,6 +1886,7 @@ mod tests {
hosts: None,
server_threads: None,
processing_threads: None,
max_payload: None,
}),
ipc: Some(Ipc {
disable: None,
Expand Down
4 changes: 4 additions & 0 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions parity/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -64,6 +65,7 @@ impl Default for HttpConfiguration {
hosts: Some(vec![]),
server_threads: 1,
processing_threads: 4,
max_payload: 5,
}
}
}
Expand Down Expand Up @@ -232,6 +234,7 @@ pub fn new_http<D: rpc_apis::Dependencies>(
rpc::RpcExtractor,
middleware,
conf.server_threads,
conf.max_payload,
);

match start_result {
Expand Down
4 changes: 3 additions & 1 deletion rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions rpc/src/tests/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fn serve(handler: Option<MetaIoHandler<Metadata>>) -> Server<HttpServer> {
}
}),
1,
5,
).unwrap())
}

Expand Down