Skip to content

Specify a Content-Type header on stream type requests when th epayload type is known#292

Merged
sergey-tihon merged 2 commits intofsprojects:masterfrom
Numpsy:octet-content
Feb 15, 2026
Merged

Specify a Content-Type header on stream type requests when th epayload type is known#292
sergey-tihon merged 2 commits intofsprojects:masterfrom
Numpsy:octet-content

Conversation

@Numpsy
Copy link
Contributor

@Numpsy Numpsy commented Feb 15, 2026

refs #291

I believe that the content-type header needs to be set on the Content itself rather than in the general request headers?

This is done already for text and (I think) form type posts, but not for streams.
There is code at

if not <| msg.Headers.TryAddWithoutValidation(name, value) then
which tries to set the Content-Type at the request level but the values don't seem to actually be sent in the request from my testing.
Maybe fillHeaders could be changed to handle the content-type headers differently, but I think this way is more consistent with how toStringContent and toTextContent work.

@sergey-tihon sergey-tihon marked this pull request as ready for review February 15, 2026 18:17
Copilot AI review requested due to automatic review settings February 15, 2026 18:17
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

This pull request fixes an issue where Content-Type headers were not being properly set on stream-based HTTP requests. The fix ensures that when a payload type is known for stream requests, the Content-Type header is set directly on the StreamContent object rather than only on the request headers.

Changes:

  • Modified toStreamContent function to accept a content type parameter and set it on the StreamContent's headers
  • Updated the call site in OperationCompiler to pass the payload MIME type to toStreamContent
  • Enhanced test server endpoint to validate that Content-Type headers are being sent correctly

Reviewed changes

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

File Description
src/SwaggerProvider.Runtime/RuntimeHelpers.fs Added contentType parameter to toStreamContent and logic to set Content-Type header on StreamContent when provided
src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs Updated toStreamContent call to pass payloadMime as the content type parameter
tests/Swashbuckle.WebApi.Server/Controllers/FileController.fs Modified test endpoint to validate Content-Type header is "application/octet-stream" and return appropriate error status when missing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sergey-tihon sergey-tihon merged commit 43c1017 into fsprojects:master Feb 15, 2026
8 checks passed
@Numpsy Numpsy deleted the octet-content branch February 15, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants