Open
Description
Description
Consider the following client sending a POST request with no body:
public interface TestFeignClient {
@RequestLine("POST /post")
String testPost();
}
Starting from Feign 12.0 requests from such clients contain an additional header Content-Type: application/x-www-form-urlencoded
, which seems to be:
- unexpected - why such type? (see also these discussions on Stack Overflow - #1, #2)
- a breaking change (not listed in the 12.0 release notes), that can cause errors such as "Media type not supported" on the server side
Expected behavior
POST requests with no body should by default add Content-Length: 0
header (as described in #1229), but no Content-Type
header.
Steps to reproduce
See a minimal example at https://github.com/mgr32/feign-post-empty-body-issue.
Analysis
- In Feign 11.10 when a request has no body, Feign’s
Client
does not send anything to outputStream (code), and JDK classHttpUrlConnection
does not addContent-type
in this case (the if here does not match becauseposter == null
) - In Feign >= 12.0 when a request has no body and the request method is POST, Feign’s
Client
sends an empty array to outputStream (code), and JDK classHttpUrlConnection
addsContent-type
in this case (the if here matches becauseposter != null
) - The change that modifies the behavior is described as a bugfix for the lack of
Content-Length
header for POSTs with an empty body - issue #1229, PR #1778. It indeed addsContent-Length
, but also theContent-Type
.