A DESCRIPTION OF THE PROBLEM :
Using HttpRequest.newBuilder() to create a simple GET() request, and executing it using HttpClient's send() method sends an HTTP 1.1 header containing the content-length: 0 header+value.
Quite some services die on this header because they do not expect a body related header for a get.
The code in question is in Http1Request method headers() which contains:
if (contentLength == 0) {
systemHeadersBuilder.setHeader("Content-Length", "0");
} else if (contentLength > 0) {
systemHeadersBuilder.setHeader("Content-Length", Long.toString(contentLength));
streaming = false;
} else {
streaming = true;
systemHeadersBuilder.setHeader("Transfer-encoding", "chunked");
}
This always sends a body related header. It should probably skip this part altogether for a GET.
FREQUENCY : always
Using HttpRequest.newBuilder() to create a simple GET() request, and executing it using HttpClient's send() method sends an HTTP 1.1 header containing the content-length: 0 header+value.
Quite some services die on this header because they do not expect a body related header for a get.
The code in question is in Http1Request method headers() which contains:
if (contentLength == 0) {
systemHeadersBuilder.setHeader("Content-Length", "0");
} else if (contentLength > 0) {
systemHeadersBuilder.setHeader("Content-Length", Long.toString(contentLength));
streaming = false;
} else {
streaming = true;
systemHeadersBuilder.setHeader("Transfer-encoding", "chunked");
}
This always sends a body related header. It should probably skip this part altogether for a GET.
FREQUENCY : always
- duplicates
-
JDK-8283605 HttpClient adding Content-Length: 0 to GET requests
-
- Closed
-