Even after explicitly configuring Netty’s maxHeaderSize and maxInitialLineLength in a Spring Cloud Gateway project, large HTTP headers still trigger connection closure errors such as:
reactor.netty.http.client.PrematureCloseException: Connection prematurely closed BEFORE response
It seems the configured limits are not being applied to the Netty HTTP server inside Spring Cloud Gateway.
What Was Tried
Added in configuration class:
httpServer.httpRequestDecoder(spec ->
spec.maxHeaderSize(32 * 1024).maxInitialLineLength(16 * 1024)
);
Tried:
server:
max-http-header-size: 32768
Tried adding:
.maxHeaderSize(32 * 1024)
and
.maxInitialLineLength(16 * 1024)
on both client and server side.
Despite all of the above, the issue persists — large request headers (~>4KB) still cause premature connection closure.
The configured header size (e.g., 32KB) should be applied to the embedded Netty server and client, allowing the Gateway to handle larger headers gracefully.
Actual Behavior
Gateway still closes the connection when header size exceeds default Netty limit (8KB).
Debug logs show default Netty values, not the overridden ones.
Error stack shows: