From 8682bb6c858fbcff2f0070c241ce6aae030753a3 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Tue, 20 Feb 2024 14:34:20 +0100 Subject: [PATCH] align maximum body size between Websock and HTTP transports (#211) HTTP has a 128 MB limit, while websock uses the library default (20 MB). Align both to 128 MB. This should be enough for an Ethereum `getPayload` with 6 blobs, all hex encoded binary + JSON overhead. --- json_rpc/client.nim | 2 ++ json_rpc/clients/httpclient.nim | 7 ++----- json_rpc/clients/websocketclientimpl.nim | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/json_rpc/client.nim b/json_rpc/client.nim index 277b7f7..114a899 100644 --- a/json_rpc/client.nim +++ b/json_rpc/client.nim @@ -28,6 +28,8 @@ export ResponseBatchRx, results +const MaxMessageBodyBytes* = 128 * 1024 * 1024 # 128 MB (JSON encoded) + type RpcBatchItem* = object meth*: string diff --git a/json_rpc/clients/httpclient.nim b/json_rpc/clients/httpclient.nim index d672336..ddd0bc5 100644 --- a/json_rpc/clients/httpclient.nim +++ b/json_rpc/clients/httpclient.nim @@ -33,9 +33,6 @@ type maxBodySize: int getHeaders: GetJsonRpcRequestHeaders -const - MaxHttpRequestSize = 128 * 1024 * 1024 # maximum size of HTTP body in octets - {.push gcsafe, raises: [].} # ------------------------------------------------------------------------------ @@ -43,7 +40,7 @@ const # ------------------------------------------------------------------------------ proc new( - T: type RpcHttpClient, maxBodySize = MaxHttpRequestSize, secure = false, + T: type RpcHttpClient, maxBodySize = MaxMessageBodyBytes, secure = false, getHeaders: GetJsonRpcRequestHeaders = nil, flags: HttpClientFlags = {}): T = var moreFlags: HttpClientFlags @@ -132,7 +129,7 @@ proc callImpl(client: RpcHttpClient, reqBody: string): Future[string] {.async.} # ------------------------------------------------------------------------------ proc newRpcHttpClient*( - maxBodySize = MaxHttpRequestSize, secure = false, + maxBodySize = MaxMessageBodyBytes, secure = false, getHeaders: GetJsonRpcRequestHeaders = nil, flags: HttpClientFlags = {}): RpcHttpClient = RpcHttpClient.new(maxBodySize, secure, getHeaders, flags) diff --git a/json_rpc/clients/websocketclientimpl.nim b/json_rpc/clients/websocketclientimpl.nim index cef9384..59fb07e 100644 --- a/json_rpc/clients/websocketclientimpl.nim +++ b/json_rpc/clients/websocketclientimpl.nim @@ -84,7 +84,7 @@ proc processData(client: RpcWebSocketClient) {.async.} = let ws = client.transport try: while ws.readyState != ReadyState.Closed: - var value = await ws.recvMsg() + var value = await ws.recvMsg(MaxMessageBodyBytes) if value.len == 0: # transmission ends