From f7ffe6d5f47cedde076003ae2515848021ce5c16 Mon Sep 17 00:00:00 2001 From: codemasterover9000 <25741433+codemasterover9000@users.noreply.github.com> Date: Fri, 31 May 2024 14:03:29 +0200 Subject: [PATCH] Make rpc serialization chunk size configurable (#9961) Make the RPC chunk size configurable through a system property `gwt.rpc.maxPayloadChunkSize`. This allows implementors to circumvent the RPC protocol version to fallback to version 7 on large payloads. Which in the current client implementation uses unsafe javascript eval, preventing proper operation on sites with CSP's restricting `unsafe-eval`. Workaround #9578 Co-authored-by: codemasterover9000 --- .../server/rpc/impl/ServerSerializationStreamWriter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/user/src/com/google/gwt/user/server/rpc/impl/ServerSerializationStreamWriter.java b/user/src/com/google/gwt/user/server/rpc/impl/ServerSerializationStreamWriter.java index 5e29935e368..93d2771f874 100644 --- a/user/src/com/google/gwt/user/server/rpc/impl/ServerSerializationStreamWriter.java +++ b/user/src/com/google/gwt/user/server/rpc/impl/ServerSerializationStreamWriter.java @@ -48,11 +48,11 @@ public final class ServerSerializationStreamWriter extends * array literals. */ public static class LengthConstrainedArray { - public static final int MAXIMUM_ARRAY_LENGTH = 1 << 15; private static final String POSTLUDE = "])"; private static final String PRELUDE = "].concat(["; private final StringBuffer buffer; + private final int maximumArrayLength = Integer.getInteger("gwt.rpc.maxPayloadChunkSize", 1 << 15); private int count = 0; private boolean needsComma = false; private int total = 0; @@ -68,8 +68,8 @@ public LengthConstrainedArray(int capacityGuess) { public void addToken(CharSequence token) { total++; - if (count++ == MAXIMUM_ARRAY_LENGTH) { - if (total == MAXIMUM_ARRAY_LENGTH + 1) { + if (count++ == maximumArrayLength) { + if (total == maximumArrayLength + 1) { buffer.append(PRELUDE); javascript = true; } else { @@ -106,7 +106,7 @@ public void setJavaScript(boolean javascript) { @Override public String toString() { - if (total > MAXIMUM_ARRAY_LENGTH) { + if (total > maximumArrayLength) { return "[" + buffer.toString() + POSTLUDE; } else { return "[" + buffer.toString() + "]";