From 67ebee3bdf2c51314b00b40ab2acbaa61ef4579a Mon Sep 17 00:00:00 2001 From: Ashish Kumar Date: Fri, 29 May 2026 12:40:46 +0530 Subject: [PATCH 1/2] Make request buffer cap configurable; raise default to 64 MB The hard-coded 5 MB cap in getMaximumRequestBufferSizeInBytes() makes Netty's HttpObjectAggregator reject any request body over 5 MB with HTTP 413 before any filter runs. This breaks customer flows such as /api/index/v1/indexdocuments where payloads commonly exceed 5 MB (e.g. Ericsson sending ~28 MB documents). Read the cap from MAX_REQUEST_BUFFER_BYTES (positive integer, bytes) and default to 64 MB. Invalid or non-positive values log a warning and fall back to the default. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../DynamicHttpFiltersSourceAdapter.java | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/glean/proxy/DynamicHttpFiltersSourceAdapter.java b/src/main/java/com/glean/proxy/DynamicHttpFiltersSourceAdapter.java index 0ed9cc2..f1bae96 100644 --- a/src/main/java/com/glean/proxy/DynamicHttpFiltersSourceAdapter.java +++ b/src/main/java/com/glean/proxy/DynamicHttpFiltersSourceAdapter.java @@ -37,14 +37,43 @@ public DynamicHttpFiltersSourceAdapter(FilterConfiguration config) { debugFilters = new ArrayList<>(config.debugFilters()); } - // Adding a 5 MB buffer to ensure the HttpRequest is aggregated. Without this, the request may be - // received in chunks. This is necessary because we handle proxy-to-server connections ourselves - // for requests coming from the customer. By enabling aggregation, we avoid having to manually - // handle chunked requests. Note that the requests with size greater than 5 MB will automatically - // be rejected at an upper layer. + // Aggregate the request body so filters can operate on a FullHttpRequest. Requests larger than + // this cap are rejected with HTTP 413 by Netty's HttpObjectAggregator before any filter runs. + // Override the cap via MAX_REQUEST_BUFFER_BYTES — required for endpoints like + // /api/index/v1/indexdocuments where customers send payloads well over the default. + private static final int DEFAULT_MAX_REQUEST_BUFFER_BYTES = 64 * 1024 * 1024; // 64 MB + + private static final int MAX_REQUEST_BUFFER_BYTES = resolveMaxRequestBufferBytes(); + + private static int resolveMaxRequestBufferBytes() { + String raw = System.getenv("MAX_REQUEST_BUFFER_BYTES"); + if (raw == null || raw.isBlank()) { + return DEFAULT_MAX_REQUEST_BUFFER_BYTES; + } + try { + int parsed = Integer.parseInt(raw.trim()); + if (parsed <= 0) { + logger.warning( + "MAX_REQUEST_BUFFER_BYTES must be positive; got " + + parsed + + ". Falling back to default " + + DEFAULT_MAX_REQUEST_BUFFER_BYTES); + return DEFAULT_MAX_REQUEST_BUFFER_BYTES; + } + return parsed; + } catch (NumberFormatException e) { + logger.warning( + "MAX_REQUEST_BUFFER_BYTES is not a valid integer: '" + + raw + + "'. Falling back to default " + + DEFAULT_MAX_REQUEST_BUFFER_BYTES); + return DEFAULT_MAX_REQUEST_BUFFER_BYTES; + } + } + @Override public int getMaximumRequestBufferSizeInBytes() { - return 5 * 1024 * 1024; // 5 mb + return MAX_REQUEST_BUFFER_BYTES; } @Override From 31bedf86101d4b130fa1983dffde1a0cdd5c5904 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Date: Fri, 29 May 2026 13:31:00 +0530 Subject: [PATCH 2/2] Keep default at 5 MB; only allow override via env var Per review feedback, leave the default cap unchanged so existing deployments behave identically. Customers needing larger payloads (e.g. Ericsson on /api/index/v1/indexdocuments) set MAX_REQUEST_BUFFER_BYTES explicitly. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../com/glean/proxy/DynamicHttpFiltersSourceAdapter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/glean/proxy/DynamicHttpFiltersSourceAdapter.java b/src/main/java/com/glean/proxy/DynamicHttpFiltersSourceAdapter.java index f1bae96..58d745c 100644 --- a/src/main/java/com/glean/proxy/DynamicHttpFiltersSourceAdapter.java +++ b/src/main/java/com/glean/proxy/DynamicHttpFiltersSourceAdapter.java @@ -39,9 +39,9 @@ public DynamicHttpFiltersSourceAdapter(FilterConfiguration config) { // Aggregate the request body so filters can operate on a FullHttpRequest. Requests larger than // this cap are rejected with HTTP 413 by Netty's HttpObjectAggregator before any filter runs. - // Override the cap via MAX_REQUEST_BUFFER_BYTES — required for endpoints like - // /api/index/v1/indexdocuments where customers send payloads well over the default. - private static final int DEFAULT_MAX_REQUEST_BUFFER_BYTES = 64 * 1024 * 1024; // 64 MB + // Override the default 5 MB cap via MAX_REQUEST_BUFFER_BYTES — required for endpoints like + // /api/index/v1/indexdocuments where customers send payloads well over 5 MB. + private static final int DEFAULT_MAX_REQUEST_BUFFER_BYTES = 5 * 1024 * 1024; // 5 MB private static final int MAX_REQUEST_BUFFER_BYTES = resolveMaxRequestBufferBytes();