Skip to content

improve json accept header processing #102

Description

@eviltester

I want Thingifier to parse and apply Accept headers correctly for JSON, XML, wildcards, quality values, and structured +json media types, so API responses use a supported representation and reject unsupported JSON-shaped media types such as application/problem+json.

Background
Thingifier currently supports standard API representations such as application/json and application/xml. Some Accept headers can still be JSON-related without being application/json, e.g. application/*+json, application/problem+json, or vendor types like application/vnd.api+json. These should not automatically be treated as supported unless Thingifier has an explicit representation writer for them.

Required Behavior

  • Accept: application/json returns JSON with Content-Type: application/json.
  • Missing Accept or Accept: */* returns the existing default representation, normally application/json.
  • Accept: application/xml returns XML when the endpoint supports XML.
  • Accept headers with multiple values must respect q values.
  • q=0 means “not acceptable” and must not be selected.
  • Unsupported media types must be ignored when a supported alternative is present.
  • If no acceptable supported representation exists, return 406 Not Acceptable.

Structured JSON Rules

  • Do not treat every +json media type as application/json.
  • application/problem+json, application/vnd.api+json, application/hal+json, and similar types should return 406 Not Acceptable unless Thingifier explicitly supports that exact representation.
  • Accept: application/*+json means the client accepts structured +json media types. It should not match plain application/json.
  • If Thingifier later adds a concrete +json representation, e.g. application/problem+json, then application/*+json may match that supported concrete type.

Examples

  • Accept: application/json, application/problem+json returns application/json.
  • Accept: application/problem+json, application/json;q=0.5 returns application/json.
  • Accept: application/problem+json returns 406.
  • Accept: application/*+json returns 406 unless a supported +json representation exists.
  • Accept: application/json;q=0, application/xml returns XML.
  • Accept: application/json;q=0 returns 406.

Acceptance Criteria

  • Add an Accept header parser that handles comma-separated media ranges, parameters, and q values.
  • Add content negotiation tests for exact matches, wildcards, unsupported media types, +json suffix types, and q=0.
  • Keep existing default JSON behavior for no Accept and */*.
  • Ensure application/problem+json is rejected until explicitly implemented.
  • Ensure chosen response Content-Type matches a representation Thingifier can actually serialize.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions