-
Notifications
You must be signed in to change notification settings - Fork 740
Open
Labels
status: waiting-for-triageUntriaged issueUntriaged issue
Description
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:
Metadata
Metadata
Assignees
Labels
status: waiting-for-triageUntriaged issueUntriaged issue