Specify a Content-Type header on stream type requests when th epayload type is known#292
Merged
sergey-tihon merged 2 commits intofsprojects:masterfrom Feb 15, 2026
Merged
Conversation
Numpsy
commented
Feb 15, 2026
Contributor
There was a problem hiding this comment.
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
toStreamContentfunction 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
SwaggerProvider/src/SwaggerProvider.Runtime/RuntimeHelpers.fs
Line 221 in d9e71a0
Maybe
fillHeaderscould be changed to handle the content-type headers differently, but I think this way is more consistent with howtoStringContentandtoTextContentwork.