Skip to content

POST requests with empty body have "Content-Type: application/x-www-form-urlencoded" header since Feign 12.0 #2068

Open
@mgr32

Description

@mgr32

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 class HttpUrlConnection does not add Content-type in this case (the if here does not match because poster == 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 class HttpUrlConnection adds Content-type in this case (the if here matches because poster != 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 adds Content-Length, but also the Content-Type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected or incorrect behaviorhelp wantedIssues we need help with tackling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions