diff options
Diffstat (limited to 'rpc/http.go')
-rw-r--r-- | rpc/http.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/rpc/http.go b/rpc/http.go index 44e2ad6ab..857cf3221 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -9,10 +9,14 @@ import ( var rpchttplogger = logger.NewLogger("RPC-HTTP") +const ( + jsonrpcver = "2.0" + maxSizeReqLength = 1024 * 1024 // 1MB +) + // JSONRPC returns a handler that implements the Ethereum JSON-RPC API. func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler { var json JsonWrapper - const jsonrpcver = "2.0" api := NewEthereumApi(pipe, dataDir) return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { @@ -20,6 +24,12 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler { rpchttplogger.DebugDetailln("Handling request") + if req.ContentLength > maxSizeReqLength { + jsonerr := &RpcErrorObject{-32700, "Error: Request too large"} + json.Send(w, &RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr}) + return + } + reqParsed, reqerr := json.ParseRequestBody(req) if reqerr != nil { jsonerr := &RpcErrorObject{-32700, "Error: Could not parse request"} |