Skip to content

HttpRequestSnippet incorrectly infers Content-Type for POST/PUT/PATCH requests without a body #1017

Closed as not planned

Description

@banseok1216

Problem

HttpRequestSnippet currently inserts a 'Content-Type: application/x-www-form-urlencoded' header in the following scenario:

  • The method is POST/PUT/PATCH
  • No Content-Type header is provided
  • No request body
  • No request parameters included in the URI

Example of the generated documentation:

POST /foo HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: localhost

However, the actual request had no Content-Type header, and Spring MVC would also receive it without one.
Since HTTP does not define a default media type and Spring does not infer one, this results in documentation that doesn’t match the real request.

Expected behavior

When a request has:

  • no Content-Type header
  • no body
  • no multipart parts

REST Docs should not add a Content-Type header automatically.

Only Content-Type values explicitly present in the request should be documented.

Minimal reproduction

new HttpRequestSnippet().document(
    operationBuilder
        .request("http://localhost/foo")
        .method("POST")
        .build()
);

Expected output:

POST /foo HTTP/1.1
Host: localhost

Actual output:

POST /foo HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: localhost

Why this matters

  • REST Docs should document the actual HTTP request sent by the client.
  • Spring MVC does not assume application/x-www-form-urlencoded when no Content-Type is provided.
  • Injecting a Content-Type that never existed can lead to misleading or incorrect API documentation.

Related issues

This problem appears to be related to the behavior described in:

Activity

  1. added a commit that references this issue on Feb 4, 2026
    af92638
  2. wilkinsona commented on Apr 7, 2026

    @wilkinsona
    Member

    Closing in favor of #1018. Thanks for the PR, @banseok1216.

  3. added
    status: superseded
    and removed on Apr 7, 2026
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

    status: supersededtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions