Skip to content

Set the "Accept" request header to the specified type, rathern than a… - #290

Merged
sergey-tihon merged 2 commits into
fsprojects:masterfrom
Numpsy:accepts_mime
Feb 15, 2026
Merged

sergey-tihon merged 2 commits into
fsprojects:masterfrom
Numpsy:accepts_mime

Conversation

@Numpsy

@Numpsy Numpsy commented Feb 9, 2026 •

Copy link
Copy Markdown
Contributor

…lways ApplicationJson

When doing some tests with a client for an API that returns plain text, I noticed that the Accept header on SwaggerProvider requests always seemed to be set to application/json rather than the text type specified in the OpenApi spec, and then I saw this checking if retMime is specified but then always using ApplicationJson and wondered if that's correct?

If this is an issue then maybe it could also be tested with something like

[<Route("api/[controller]")>]
[<ApiController>]
type ReturnCsvController() =
    inherit ControllerBase()

    [<HttpGet; Produces("text/csv")>]
    member this.Get() =
        if this.Request.Headers.Accept.Equals("text/csv") then
            "Hello,world" |> ActionResult<string>
        else
            ActionResult<string>(UnsupportedMediaTypeResult())

?

@sergey-tihon

Copy link
Copy Markdown
Member

I am OK with the fix, can you please add controller here https://github.com/fsprojects/SwaggerProvider/blob/master/tests/Swashbuckle.WebApi.Server/Controllers/ReturnTextControllers.fs and tests that verify it:

@Numpsy

Numpsy commented Feb 15, 2026

Copy link
Copy Markdown
Contributor Author

Added a couple of extra tests with controller functions that check the Accept header (two tests rather than one just to test that it handles switching rather than always being one or the other)

@Numpsy
Numpsy marked this pull request as ready for review February 15, 2026 12:33
@sergey-tihon
sergey-tihon merged commit 6850758 into fsprojects:master Feb 15, 2026
2 checks passed
@sergey-tihon

Copy link
Copy Markdown
Member

Does it fix #291 ?

@Numpsy
Numpsy deleted the accepts_mime branch February 15, 2026 12:45
@Numpsy

Numpsy commented Feb 15, 2026

Copy link
Copy Markdown
Contributor Author

This one is just about the Accept header, I think the Content-Type on stream content would be something like ad8d2a8 (I didn't have time to test it much beyond that)

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