Using the Jdk HttpClient, when no body is present in a GET or HEAD request, and that the downstream server only supports HTTP 1.1:
a Transfer-Encoding: chunked will be added to the downstream request, causing some WAF to reject it (see "Body in GET or HEAD requests" in BIG-IP ASM HTTP protocol compliance for example).
The reason seems to be a combination of the issue describe in GH-3308 that causes HTTP 1.1 exchange to be always performed in chunked mode, and the fact that the body is always set in RestClientProxyExchange.
This will cause this JdkClientHttpRequest check to think that there is a body (since body is not null and upstream Content-Length: 0 was removed if present) and will cause the addition of the Transfer-Encoding: chunked header later.
As a workaround I've implemented this fix
@Override
public ServerResponse exchange(Request request) {
var requestSpec = restClient.method(request.getMethod()).uri(request.getUri())
.headers(httpHeaders -> httpHeaders.putAll(request.getHeaders()));
if (isBodyPresent(request)) {
requestSpec.body(outputStream -> copyBody(request, outputStream));
}
return requestSpec.exchange((clientRequest, clientResponse) -> doExchange(request, clientResponse), false);
}
isBodyPresent(request) is simply checking that request.getServerRequest().servletRequest().getInputStream().available() > 0 (using upstream Content-Length or Transfer-Encoding would not work if server.http2.enabled=true).
I can submit a PR if you feel that the fix is relevant.
Using the
Jdk HttpClient, when no body is present in aGETorHEADrequest, and that the downstream server only supportsHTTP 1.1:a
Transfer-Encoding: chunkedwill be added to the downstream request, causing some WAF to reject it (see "Body in GET or HEAD requests" in BIG-IP ASM HTTP protocol compliance for example).The reason seems to be a combination of the issue describe in GH-3308 that causes
HTTP 1.1exchange to be always performed inchunkedmode, and the fact that the body is always set in RestClientProxyExchange.This will cause this JdkClientHttpRequest check to think that there is a body (since body is not null and upstream
Content-Length: 0was removed if present) and will cause the addition of theTransfer-Encoding: chunkedheader later.As a workaround I've implemented this fix
isBodyPresent(request)is simply checking thatrequest.getServerRequest().servletRequest().getInputStream().available() > 0(using upstreamContent-LengthorTransfer-Encodingwould not work ifserver.http2.enabled=true).I can submit a PR if you feel that the fix is relevant.