Pretty much the title.
We upgraded spring boot from 3.1.x to 3.2.5 and we see the behavior of Rest template has been changed.
For a POST request with empty body, the rest template is not adding the header Content-Length
with value 0.
What’s worse? Despite adding it explicitly to the headers, Rest template is discarding it for some reason. Following are the before and after logs for the same.
The logs are taken from class DEBUG - o.a.h.c.h.i.Wire.wire(92) - http-outgoing-0
From spring boot 3.1.10
---- >> "POST /oauth2/token HTTP/1.1[r][n]"
---- >> "Accept: text/plain, application/json, application/*+json, */*[r][n]"
---- >> "Authorization: Basic ******=[r][n]"
---- >> "grant_type: client_credentials[r][n]"
---- >> "scope: you don't need this[r][n]"
---- >> "Content-Type: application/x-www-form-urlencoded[r][n]"
---- >> "Accept-Encoding: gzip, x-gzip, deflate[r][n]"
---- >> "Content-Length: 0[r][n]"
---- >> "Host: this one too[r][n]"
---- >> "Connection: keep-alive[r][n]"
---- >> "User-Agent: Apache-HttpClient/5.2.1 (Java/17.0.10)[r][n]"
---- >> "[r][n]"
After spring upgrade::
From spring boot 3.2.5
---- >> "POST /oauth2/token HTTP/1.1[r][n]"
---- >> "Accept: text/plain, application/json, application/*+json, */*[r][n]"
---- >> "Authorization: Basic ****=[r][n]"
---- >> "grant_type: client_credentials[r][n]"
---- >> "scope: you don't need this[r][n]"
---- >> "Content-Type: application/x-www-form-urlencoded[r][n]"
---- >> "Accept-Encoding: gzip, x-gzip, deflate[r][n]"
---- >> "Host: this one too[r][n]"
---- >> "Connection: keep-alive[r][n]"
---- >> "User-Agent: Apache-HttpClient/5.2.1 (Java/17.0.10)[r][n]"
I don’t see anything related to this change mentioned in the 3.2 release notes.
How do I fix this now? When the client discards the length header despite adding it explicitly?