Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP: Should not be send Content-Type when is used http method without payload when use asXXX() #4429

Closed
gemiusz opened this issue Jun 1, 2023 · 2 comments

Comments

@gemiusz
Copy link
Contributor

gemiusz commented Jun 1, 2023

Regarding to RFC7231 Section 3.1.1.5 when is used asXXX() when is creating request should be checked if request have .body() if not there shouldn't be set header content-type.
At this moment is always set.

@slandelle
Copy link
Member

Mixed feelings: asJson is clearly documented as a shortcut for

http("name").post("/")
  .header("accept", "application/json")
  .header("content-type", "application/json")

But then, people often don't read the documentation...

@slandelle
Copy link
Member

I ended up favoring ease of use for the end user and doing as you advised.

Thanks @gemiusz !

slandelle added a commit that referenced this issue Aug 14, 2023
 #4429

Motivation:

Users might use `asXxx` even when they're not passing a body, just to define the `accept` header.

Modification:

Remove `content-type` when the request doesn't have a body.
@slandelle slandelle modified the milestones: 3.10.1, 3.10.0 Nov 11, 2023
slandelle added a commit that referenced this issue Jan 15, 2024
… body is empty, close #4509

Motivation:

As of #4429, we're aggressively removing request content-type header when request body is empty.
This is wrong, some content-types have valid empty string value, such as application/x-www-form-urlencoded.

Let's only not add a request content-type when using asJson and asXml when there's no body as an empty string is not a valid content for these encodings.

Modification:

Introduce HeadersBuiltIn that's only resolved when building the request.
slandelle added a commit that referenced this issue Jan 15, 2024
… body is empty, close #4509

Motivation:

As of #4429, we're aggressively removing request content-type header when request body is empty.
This is wrong, some content-types have valid empty string value, such as application/x-www-form-urlencoded.

Let's only not add a request content-type when using asJson and asXml when there's no body as an empty string is not a valid content for these encodings.

Modification:

Introduce HeadersBuiltIn that's only resolved when building the request.
slandelle added a commit that referenced this issue Jan 19, 2024
… body is empty, close #4509

Motivation:

As of #4429, we're aggressively removing request content-type header when request body is empty.
This is wrong, some content-types have valid empty string value, such as application/x-www-form-urlencoded.

Let's only not add a request content-type when using asJson and asXml when there's no body as an empty string is not a valid content for these encodings.

Modification:

Introduce HeadersBuiltIn that's only resolved when building the request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants