mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd/geth: let retesteth increase the payload size
This commit is contained in:
parent
6bd896a97f
commit
9b10418312
2 changed files with 20 additions and 6 deletions
|
|
@ -68,6 +68,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type RetestethTestAPI interface {
|
type RetestethTestAPI interface {
|
||||||
|
SetRPCPayloadSize(ctx context.Context, size int) (int, error)
|
||||||
SetChainParams(ctx context.Context, chainParams ChainParams) (bool, error)
|
SetChainParams(ctx context.Context, chainParams ChainParams) (bool, error)
|
||||||
MineBlocks(ctx context.Context, number uint64) (bool, error)
|
MineBlocks(ctx context.Context, number uint64) (bool, error)
|
||||||
ModifyTimestamp(ctx context.Context, interval uint64) (bool, error)
|
ModifyTimestamp(ctx context.Context, interval uint64) (bool, error)
|
||||||
|
|
@ -271,6 +272,10 @@ func (e *NoRewardEngine) Close() error {
|
||||||
return e.inner.Close()
|
return e.inner.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *RetestethAPI) SetRPCPayloadSize(ctx context.Context, size int) (int, error) {
|
||||||
|
return rpc.SetMaxRequestContentLength(size)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *RetestethAPI) SetChainParams(ctx context.Context, chainParams ChainParams) (bool, error) {
|
func (api *RetestethAPI) SetChainParams(ctx context.Context, chainParams ChainParams) (bool, error) {
|
||||||
// Clean up
|
// Clean up
|
||||||
if api.blockchain != nil {
|
if api.blockchain != nil {
|
||||||
|
|
|
||||||
21
rpc/http.go
21
rpc/http.go
|
|
@ -35,14 +35,23 @@ import (
|
||||||
"github.com/rs/cors"
|
"github.com/rs/cors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const contentType = "application/json"
|
||||||
maxRequestContentLength = 1024 * 512
|
|
||||||
contentType = "application/json"
|
var maxRequestContentLength = 1024 * 512
|
||||||
)
|
|
||||||
|
|
||||||
// https://www.jsonrpc.org/historical/json-rpc-over-http.html#id13
|
// https://www.jsonrpc.org/historical/json-rpc-over-http.html#id13
|
||||||
var acceptedContentTypes = []string{contentType, "application/json-rpc", "application/jsonrequest"}
|
var acceptedContentTypes = []string{contentType, "application/json-rpc", "application/jsonrequest"}
|
||||||
|
|
||||||
|
// SetMaxRequestContentLength changes the maximum payload size to be accepted
|
||||||
|
// by the RPC system. This is only to be changed for tests.
|
||||||
|
func SetMaxRequestContentLength(length int) (int, error) {
|
||||||
|
if length < 0 {
|
||||||
|
return maxRequestContentLength, fmt.Errorf("Invalid RPC payload length %d", length)
|
||||||
|
}
|
||||||
|
maxRequestContentLength = length
|
||||||
|
return maxRequestContentLength, nil
|
||||||
|
}
|
||||||
|
|
||||||
type httpConn struct {
|
type httpConn struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
req *http.Request
|
req *http.Request
|
||||||
|
|
@ -193,7 +202,7 @@ type httpServerConn struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHTTPServerConn(r *http.Request, w http.ResponseWriter) ServerCodec {
|
func newHTTPServerConn(r *http.Request, w http.ResponseWriter) ServerCodec {
|
||||||
body := io.LimitReader(r.Body, maxRequestContentLength)
|
body := io.LimitReader(r.Body, int64(maxRequestContentLength))
|
||||||
conn := &httpServerConn{Reader: body, Writer: w, r: r}
|
conn := &httpServerConn{Reader: body, Writer: w, r: r}
|
||||||
return NewJSONCodec(conn)
|
return NewJSONCodec(conn)
|
||||||
}
|
}
|
||||||
|
|
@ -275,7 +284,7 @@ func validateRequest(r *http.Request) (int, error) {
|
||||||
if r.Method == http.MethodPut || r.Method == http.MethodDelete {
|
if r.Method == http.MethodPut || r.Method == http.MethodDelete {
|
||||||
return http.StatusMethodNotAllowed, errors.New("method not allowed")
|
return http.StatusMethodNotAllowed, errors.New("method not allowed")
|
||||||
}
|
}
|
||||||
if r.ContentLength > maxRequestContentLength {
|
if r.ContentLength > int64(maxRequestContentLength) {
|
||||||
err := fmt.Errorf("content length too large (%d>%d)", r.ContentLength, maxRequestContentLength)
|
err := fmt.Errorf("content length too large (%d>%d)", r.ContentLength, maxRequestContentLength)
|
||||||
return http.StatusRequestEntityTooLarge, err
|
return http.StatusRequestEntityTooLarge, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue