[core] Allow setting content-type header even if there is no request body#37181
[core] Allow setting content-type header even if there is no request body#37181timovv merged 3 commits intoAzure:mainfrom
Conversation
There was a problem hiding this comment.
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-typeheader 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. |
|
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 |
|
@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. |
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