Skip to content

[core] Allow setting content-type header even if there is no request body#37181

Merged
timovv merged 3 commits intoAzure:mainfrom
timovv:core/allow-content-type-with-no-body
Jan 29, 2026
Merged

[core] Allow setting content-type header even if there is no request body#37181
timovv merged 3 commits intoAzure:mainfrom
timovv:core/allow-content-type-with-no-body

Conversation

@timovv
Copy link
Member

@timovv timovv commented Jan 28, 2026

Description

See #37179. A service requires a content type be specified even though the request has no body. This is unusual but if customers are passing a custom content type value with no body then I don't see why this shouldn't be allowed, not sure if others have thoughts here?

Packages impacted by this PR

  • @typespec/ts-http-runtime

@timovv timovv marked this pull request as ready for review January 28, 2026 17:41
@timovv timovv requested a review from a team as a code owner January 28, 2026 17:41
Copilot AI review requested due to automatic review settings January 28, 2026 17:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables callers of @typespec/ts-http-runtime’s sendRequest helper to preserve/set an explicit Content-Type header even when the request has no body, addressing services that require Content-Type for body-less requests (Issue #37179).

Changes:

  • Update content-type resolution so it’s only inferred from the body when a body is actually present, while still honoring explicit contentType/headers["content-type"].
  • Always apply an explicitly resolved content-type header regardless of whether a request body exists.
  • Add/adjust tests and document the fix in the changelog.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
sdk/core/ts-http-runtime/src/client/sendRequest.ts Adjusts content-type selection and header application logic in request construction.
sdk/core/ts-http-runtime/test/client/sendRequest.spec.ts Updates/adds tests to validate Content-Type behavior when no request body is provided.
sdk/core/ts-http-runtime/CHANGELOG.md Notes the bug fix in the unreleased changelog.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@xirzec
Copy link
Member

xirzec commented Jan 28, 2026

Glancing at the spec I don't see any concerns with sending this without a body content: https://httpwg.org/specs/rfc9110.html#field.content-type

Copy link
Member

@MaryGao MaryGao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, may I know when this will be released? we have one mgmt release blocked by this: #37048.

@timovv
Copy link
Member Author

timovv commented Jan 29, 2026

@MaryGao, we have a Core release scheduled for next week on 2/5. Would that be soon enough? If you need it sooner I can do a hotfix.

@timovv timovv merged commit 804a517 into Azure:main Jan 29, 2026
14 checks passed
@MaryGao
Copy link
Member

MaryGao commented Jan 30, 2026

@MaryGao, we have a Core release scheduled for next week on 2/5. Would that be soon enough? If you need it sooner I can do a hotfix.

The scheduled one should be fine for us, thanks a lot for this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants