4

I am reading the HTTP Header Field Definitions in order to parse accept headers properly and I am stumbling over the accept-extension field definition. They are part of indicating the accept headers precedence, which would give the following order:

text/html;level=1;param=other
// Less specific :
text/html;level=1
// Less specific:
text/html
// Even less specific
text/*

I am not sure what should happen, if a client requests text/html;level=1 but I only have a content provider for text/html. Do I send the text/html content or a 406 (Not Acceptable) error?

Daff
  • 43,734
  • 9
  • 106
  • 120
  • 2
    Note that according to the RFC, in the examples you've provided level=1 and param=other are media range parameters, and there are no accept extensions. Accept extensions are anything after the quality value, and, to the best of my knowledge, are almost totally unused in practice. – Mark Slater Jan 01 '14 at 12:44
  • Accept parameters are getting popular for API versioning, e.g. `Accept: application/json;version=1`. The `q=` quality factor is entirely optional as per [RFC7231](https://tools.ietf.org/html/rfc7231#section-5.3.2). – ioquatix Feb 04 '16 at 04:53
  • @MarkSlater is correct. From RFC7231: `The "q" parameter is necessary if any extensions (accept-ext) are present, since it acts as a separator between the two parameter sets.` – stacktracer Aug 12 '19 at 20:24

1 Answers1

2

In your example, you would send back a 406. If they can also accept a basic text/html, they should send this:

Accept: text/html, text/html;level=1 

Note that order doesn't matter, and the most specific always takes precedence.

Kylar
  • 8,876
  • 8
  • 41
  • 75
  • Thanks, sounds good, it was also my default behavior. Everything else should be working according to the RFC now :) – Daff Jan 13 '11 at 19:00
  • Good luck. Http is a fickle mistress. – Kylar Jan 13 '11 at 19:01
  • It is actually suggested in several places in the RFC that order is not irrelevant, e.g. http://stackoverflow.com/a/35181217/293815 – ioquatix Feb 04 '16 at 04:52