diff --git a/rpcserver/jsonrpc_server.go b/rpcserver/jsonrpc_server.go index 123e249..3c31ab4 100644 --- a/rpcserver/jsonrpc_server.go +++ b/rpcserver/jsonrpc_server.go @@ -45,6 +45,7 @@ type ( highPriorityKey struct{} signerKey struct{} originKey struct{} + sizeKey struct{} ) type jsonRPCRequest struct { @@ -195,6 +196,8 @@ func (h *JSONRPCHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } bodySize := len(body) + ctx = context.WithValue(ctx, sizeKey{}, bodySize) + bigRequest = bodySize > requestSizeThreshold defer func(size int) { incRequestSizeBytes(size, methodForMetrics, h.ServerName) @@ -335,3 +338,7 @@ func GetOrigin(ctx context.Context) string { } return value } + +func GetRequestSize(ctx context.Context) int { + return ctx.Value(sizeKey{}).(int) +}