Skip to content

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

Closed

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.

Activity

  1. added
    bug
    help wanted
    on Sep 13, 2024
  2. added a commit that references this issue on Aug 12, 2026
    f8f1f92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions