This is a simple project showing that POSTs with empty body are sent with Content-Type: application/x-www-form-urlencoded header in Feign >= 12.0, and no Content-Type header in Feign < 12.0.
-
Run
./gradlew clean test --info- it will run a single test that sends a POST with empty body to WireMock, and logs the headers. -
Observe the output:
PostWithEmptyBodyTest > postWithEmptyBodyTest() STANDARD_OUT WireMock received request to http://localhost:8081/post with the following headers: Accept: */* User-Agent: Java/17.0.6 Host: localhost:8081 Connection: keep-alive Content-Type: application/x-www-form-urlencoded Content-Length: 0 PostWithEmptyBodyTest > postWithEmptyBodyTest() FAILED java.lang.AssertionError: Expecting empty but was: "application/x-www-form-urlencoded" at com.example.demo.PostWithEmptyBodyTest.postWithEmptyBodyTest(PostWithEmptyBodyTest.java:49)- Note there is a header
Content-Length: 0(expected) but alsoContent-Type: application/x-www-form-urlencoded(unexpected)
- Note there is a header
-
Change
io.github.openfeign:feign-coreversion inbuild.gradlefrom12.3to11.10(last version with the old behaviour) and re-run the test. -
Observe the output:
PostWithEmptyBodyTest > postWithEmptyBodyTest() STANDARD_OUT WireMock received request to http://localhost:8081/post with the following headers: Accept: */* User-Agent: Java/17.0.6 Host: localhost:8081 Connection: keep-alive- Note there are no
Content-LengthandContent-Typeheaders.
- Note there are no