mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
cmd, node, rpc: make HTTP body limit configurable
This commit is contained in:
parent
4ff33ba1b6
commit
de887ab8a4
8 changed files with 36 additions and 2 deletions
|
|
@ -193,6 +193,7 @@ var (
|
||||||
utils.AllowUnprotectedTxs,
|
utils.AllowUnprotectedTxs,
|
||||||
utils.BatchRequestLimit,
|
utils.BatchRequestLimit,
|
||||||
utils.BatchResponseMaxSize,
|
utils.BatchResponseMaxSize,
|
||||||
|
utils.HTTPBodyLimitFlag,
|
||||||
utils.RPCTxSyncDefaultTimeoutFlag,
|
utils.RPCTxSyncDefaultTimeoutFlag,
|
||||||
utils.RPCTxSyncMaxTimeoutFlag,
|
utils.RPCTxSyncMaxTimeoutFlag,
|
||||||
utils.RPCGlobalRangeLimitFlag,
|
utils.RPCGlobalRangeLimitFlag,
|
||||||
|
|
|
||||||
|
|
@ -850,6 +850,12 @@ var (
|
||||||
Value: node.DefaultConfig.BatchResponseMaxSize,
|
Value: node.DefaultConfig.BatchResponseMaxSize,
|
||||||
Category: flags.APICategory,
|
Category: flags.APICategory,
|
||||||
}
|
}
|
||||||
|
HTTPBodyLimitFlag = &cli.IntFlag{
|
||||||
|
Name: "http.bodylimit",
|
||||||
|
Usage: "Maximum size of an HTTP RPC request body in bytes",
|
||||||
|
Value: node.DefaultConfig.HTTPBodyLimit,
|
||||||
|
Category: flags.APICategory,
|
||||||
|
}
|
||||||
|
|
||||||
// Network Settings
|
// Network Settings
|
||||||
MaxPeersFlag = &cli.IntFlag{
|
MaxPeersFlag = &cli.IntFlag{
|
||||||
|
|
@ -1350,6 +1356,10 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
|
||||||
if ctx.IsSet(BatchResponseMaxSize.Name) {
|
if ctx.IsSet(BatchResponseMaxSize.Name) {
|
||||||
cfg.BatchResponseMaxSize = ctx.Int(BatchResponseMaxSize.Name)
|
cfg.BatchResponseMaxSize = ctx.Int(BatchResponseMaxSize.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.IsSet(HTTPBodyLimitFlag.Name) {
|
||||||
|
cfg.HTTPBodyLimit = ctx.Int(HTTPBodyLimitFlag.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// setGraphQL creates the GraphQL listener interface string from the set
|
// setGraphQL creates the GraphQL listener interface string from the set
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,7 @@ func (api *adminAPI) StartHTTP(host *string, port *int, cors *string, apis *stri
|
||||||
rpcEndpointConfig: rpcEndpointConfig{
|
rpcEndpointConfig: rpcEndpointConfig{
|
||||||
batchItemLimit: api.node.config.BatchRequestLimit,
|
batchItemLimit: api.node.config.BatchRequestLimit,
|
||||||
batchResponseSizeLimit: api.node.config.BatchResponseMaxSize,
|
batchResponseSizeLimit: api.node.config.BatchResponseMaxSize,
|
||||||
|
httpBodyLimit: api.node.config.HTTPBodyLimit,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if cors != nil {
|
if cors != nil {
|
||||||
|
|
@ -259,6 +260,7 @@ func (api *adminAPI) StartWS(host *string, port *int, allowedOrigins *string, ap
|
||||||
rpcEndpointConfig: rpcEndpointConfig{
|
rpcEndpointConfig: rpcEndpointConfig{
|
||||||
batchItemLimit: api.node.config.BatchRequestLimit,
|
batchItemLimit: api.node.config.BatchRequestLimit,
|
||||||
batchResponseSizeLimit: api.node.config.BatchResponseMaxSize,
|
batchResponseSizeLimit: api.node.config.BatchResponseMaxSize,
|
||||||
|
httpBodyLimit: api.node.config.HTTPBodyLimit,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if apis != nil {
|
if apis != nil {
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,9 @@ type Config struct {
|
||||||
// interface.
|
// interface.
|
||||||
HTTPTimeouts rpc.HTTPTimeouts
|
HTTPTimeouts rpc.HTTPTimeouts
|
||||||
|
|
||||||
|
// HTTPBodyLimit is the maximum size of an HTTP request body in bytes.
|
||||||
|
HTTPBodyLimit int `toml:",omitempty"`
|
||||||
|
|
||||||
// HTTPPathPrefix specifies a path prefix on which http-rpc is to be served.
|
// HTTPPathPrefix specifies a path prefix on which http-rpc is to be served.
|
||||||
HTTPPathPrefix string `toml:",omitempty"`
|
HTTPPathPrefix string `toml:",omitempty"`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ var DefaultConfig = Config{
|
||||||
HTTPModules: []string{"net", "web3"},
|
HTTPModules: []string{"net", "web3"},
|
||||||
HTTPVirtualHosts: []string{"localhost"},
|
HTTPVirtualHosts: []string{"localhost"},
|
||||||
HTTPTimeouts: rpc.DefaultHTTPTimeouts,
|
HTTPTimeouts: rpc.DefaultHTTPTimeouts,
|
||||||
|
HTTPBodyLimit: rpc.DefaultHTTPBodyLimit,
|
||||||
WSPort: DefaultWSPort,
|
WSPort: DefaultWSPort,
|
||||||
WSModules: []string{"net", "web3"},
|
WSModules: []string{"net", "web3"},
|
||||||
BatchRequestLimit: 1000,
|
BatchRequestLimit: 1000,
|
||||||
|
|
|
||||||
|
|
@ -395,6 +395,7 @@ func (n *Node) startRPC() error {
|
||||||
rpcConfig := rpcEndpointConfig{
|
rpcConfig := rpcEndpointConfig{
|
||||||
batchItemLimit: n.config.BatchRequestLimit,
|
batchItemLimit: n.config.BatchRequestLimit,
|
||||||
batchResponseSizeLimit: n.config.BatchResponseMaxSize,
|
batchResponseSizeLimit: n.config.BatchResponseMaxSize,
|
||||||
|
httpBodyLimit: n.config.HTTPBodyLimit,
|
||||||
}
|
}
|
||||||
|
|
||||||
initHttp := func(server *httpServer, port int) error {
|
initHttp := func(server *httpServer, port int) error {
|
||||||
|
|
|
||||||
|
|
@ -324,6 +324,20 @@ func baseRpcRequest(t *testing.T, url, bodyStr string, extraHeaders ...string) *
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHTTPBodyLimit(t *testing.T) {
|
||||||
|
body := `{"jsonrpc":"2.0","id":1,"method":"rpc_modules","params":[]}`
|
||||||
|
cfg := &httpConfig{
|
||||||
|
rpcEndpointConfig: rpcEndpointConfig{
|
||||||
|
httpBodyLimit: len(body) - 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
srv := createAndStartServer(t, cfg, false, &wsConfig{}, nil)
|
||||||
|
defer srv.stop()
|
||||||
|
|
||||||
|
resp := baseRpcRequest(t, "http://"+srv.listenAddr(), body)
|
||||||
|
assert.Equal(t, http.StatusRequestEntityTooLarge, resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
type testClaim map[string]interface{}
|
type testClaim map[string]interface{}
|
||||||
|
|
||||||
func (testClaim) Valid() error {
|
func (testClaim) Valid() error {
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultBodyLimit = 5 * 1024 * 1024
|
// DefaultHTTPBodyLimit is the default maximum size of an HTTP request body.
|
||||||
contentType = "application/json"
|
DefaultHTTPBodyLimit = 5 * 1024 * 1024
|
||||||
|
defaultBodyLimit = DefaultHTTPBodyLimit
|
||||||
|
contentType = "application/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// https://www.jsonrpc.org/historical/json-rpc-over-http.html#id13
|
// https://www.jsonrpc.org/historical/json-rpc-over-http.html#id13
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue