Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

ObjectResultExecutor should hold the Accept header in higher regard #4612

@tuespetre

Description

@tuespetre

The problem behavior

Here is the rundown of the issue I'm seeing:

  1. I have a controller action decorated with [Produces("application/vnd.my-app+json; version=1")]
  2. I have a custom OutputFormatter that will say it CanWriteResult as long as the content type is application/vnd.my-app+json, regardless of media type parameter values
  3. I have RespectBrowserAcceptHeader (why the 'browser' in the name?) set to true to make sure any Accept header is respected (Just in case, I guess? It looks like maybe it only has to do with */* wildcard media types...)
  4. I send a fetch to the controller action from my browser's console with an Accept header value of application/vnd.derp and receive a 200 response with a Content-Type header value of application/vnd.my-app; version=1

The expected behavior

I would expect content negotiation to honor the Accept request header in all cases and respond with 406 whenever it cannot locate a formatter that applies to a media type specified in the Accept header, rather than responding with whatever it can muster up even when the client has explicitly declared what it will accept.

Possible workaround

In RC2, the OutputFormatterWriteContext exposes the HttpContext. A custom formatter could take advantage of that in order to properly respect the Accept header value, but this breaks the current negotiator/formatter pattern and causes the formatter to violate the Single Responsibility Principle.

In RC1, well, there's nothing that easy that I can see offhand.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions