graphql-dotnet/server

[Feature] Add proper support of Accept HTTP header

Shane32 opened this issue · 2 comments

If the request includes a supported response content type within the Accept header, the response content type should match the content type requested by the client.

See also:

Supported response content types should be:

  • application/json
  • application/graphql-response+json (current draft spec)
  • application/graphql+json (previous draft spec and v7.0 behavior) -- probably remove in some future version

@sungam3r What do you think makes the most sense here:

Option 1

Assuming the requested content-type is supported, return exactly the content-type that was passed into the Accept header.

For example, when requesting APPLICATION/JSON, return APPLICATION/JSON and not application/json; charset=utf-8.

The accept header may return a wildcard, so in those situations we would need to pick an applicable content type.

Option 2

Try to find a best match, and return a compatible content-type with the request.

For example, when requesting APPLICATION/JSON, return application/json; charset=utf-8.

The ASP.NET-provided method for determining compatibility has changed across different versions of ASP.NET. In .NET 6, the same sample above would return application/graphql-response+json; charset=utf-8 because that is considered compatible (assuming of course that we gave priority to that response). We would need to decide to either (a) use the implementation provided by whatever version of .NET is in use, or (b) copy an implementation and use that.

Note that all versions from ASP.NET 2.1 through ASP.NET 6.0 do not support a quoted charset - e.g. charset="UTF-8".

I tend to option 2.