cmd/geth: let retesteth increase the payload size

This commit is contained in:
Guillaume Ballet 2019-07-16 13:34:20 +02:00
parent 6bd896a97f
commit 9b10418312
2 changed files with 20 additions and 6 deletions

View file

@ -68,6 +68,7 @@ var (
)
type RetestethTestAPI interface {
SetRPCPayloadSize(ctx context.Context, size int) (int, error)
SetChainParams(ctx context.Context, chainParams ChainParams) (bool, error)
MineBlocks(ctx context.Context, number uint64) (bool, error)
ModifyTimestamp(ctx context.Context, interval uint64) (bool, error)
@ -271,6 +272,10 @@ func (e *NoRewardEngine) Close() error {
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) {
// Clean up
if api.blockchain != nil {

View file

@ -35,14 +35,23 @@ import (
"github.com/rs/cors"
)
const (
maxRequestContentLength = 1024 * 512
contentType = "application/json"
)
const contentType = "application/json"
var maxRequestContentLength = 1024 * 512
// https://www.jsonrpc.org/historical/json-rpc-over-http.html#id13
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 {
client *http.Client
req *http.Request
@ -193,7 +202,7 @@ type httpServerConn struct {
}
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}
return NewJSONCodec(conn)
}
@ -275,7 +284,7 @@ func validateRequest(r *http.Request) (int, error) {
if r.Method == http.MethodPut || r.Method == http.MethodDelete {
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)
return http.StatusRequestEntityTooLarge, err
}