Affects: 6.1.6
I have an API that requires sending a Content-Length: 0 when the body is null/empty.
When we previously upgraded to Spring Boot 3 / Spring 6, we changed our RestTemplate to use new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory()) as the request factory in order to ensure that a Content-Length was set.
This worked on 6.1.5, but on upgrading to 6.1.6 we are no longer sending the Content-Length header.
Stepping through the code with a debugger, this changed in 019ce44 / gh-32612.
|
if (bufferedOutput.length > 0) { |
I can force the old behavior if I do the following, which leads me to believe it is that commit (effectively, I'm trying to just skip over the new if):
- Set a breakpoint at line 58 and at line 59 of
BufferingClientHttpRequestWrapper
- (on line 58 breakpoint) in the evaluation expression window run
bufferedOutput = new byte[1];
- Continue to line 59 breakpoint
- (on line 59 breakpoint) in the evaluation expression window run
bufferedOutput = new byte[0];
Doing this then causes the Content-Length: 0 header to be sent as expected.
I tried also manually setting Content-Length: 0 as a header, but HttpComponentsClientHttpRequest does not allow that, as is explicitly ignores Content-Length as a header.
|
else if (!HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(headerName) && |
This still works as expected (Content-Length: 0 is set) when using SimpleClientHttpRequestFactory, so for now I can work around this by using new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()) instead. However, I would prefer to use HttpComponentsClientHttpRequestFactory instead of Simple if possible.
Affects: 6.1.6
I have an API that requires sending a
Content-Length: 0when the body is null/empty.When we previously upgraded to Spring Boot 3 / Spring 6, we changed our
RestTemplateto usenew BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory())as the request factory in order to ensure that aContent-Lengthwas set.This worked on 6.1.5, but on upgrading to 6.1.6 we are no longer sending the
Content-Lengthheader.Stepping through the code with a debugger, this changed in 019ce44 / gh-32612.
spring-framework/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java
Line 58 in 019ce44
I can force the old behavior if I do the following, which leads me to believe it is that commit (effectively, I'm trying to just skip over the new
if):BufferingClientHttpRequestWrapperbufferedOutput = new byte[1];bufferedOutput = new byte[0];Doing this then causes the
Content-Length: 0header to be sent as expected.I tried also manually setting
Content-Length: 0as a header, butHttpComponentsClientHttpRequestdoes not allow that, as is explicitly ignoresContent-Lengthas a header.spring-framework/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java
Line 110 in 019ce44
This still works as expected (
Content-Length: 0is set) when usingSimpleClientHttpRequestFactory, so for now I can work around this by usingnew BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())instead. However, I would prefer to useHttpComponentsClientHttpRequestFactoryinstead ofSimpleif possible.