HTTP Accept Parser

Parse media ranges, parameters, and q weights in Accept without collapsing order or choosing a representation.

Description

Accept lists media ranges and preference weights for representation negotiation.

Accept lists media ranges and preference weights for representation negotiation. Parsing retains preferences; selecting a server representation requires another step.1, 2

Parse media ranges, parameters, and q weights in Accept without collapsing order or choosing a representation.

When to use HTTP Accept Parser

Use this tool to parse media ranges, parameters, and q weights in Accept without collapsing order or choosing a representation.

Prepare the header field value, cookie records or status code requested. Supply field values without a header-name prefix and preserve syntax for the parser to inspect.

How to use HTTP Accept Parser and understand its results

  1. Prepare the header field value, cookie records or status code requested. Supply field values without a header-name prefix and preserve syntax for the parser to inspect.
  2. Enter header using the field table and calculation rules, then run the tool.
  3. Read ranges. The explanation below defines the units, signs, ordering and any flags or placeholder values.
  4. If the tool reports an input issue, correct the values and run it again. Apply the stated assumptions when interpreting a successfully returned result.
Input fieldMeaningValue type; see rules belowRequirement
headerAccept field value.string; maximum length: 1000000Required

Paste the field value. Split outside quotes/angle brackets, lowercase ranges and parameter names, and unquote/unescape non-q values. Permit */*, concrete type/* and concrete type/subtype; reject */subtype. Each range allows one unquoted q from 0 to 1 with at most three decimal digits. Remove q from returned parameters; preserve other parameter duplicates and source order. Empty comma groups are skipped.3

quality=explicit q or 1; ranges preserve header order

Units, indexing, boundary conditions and exceptional cases are defined in the calculation rules above.

Output fieldMeaningValue type
rangesMedia ranges with explicit quality values.list of object; minimum entries: 0; maximum entries: 100000
json
{
  "input": {
    "header": "text/html, application/json;q=0.8, */*;q=0.1"
  },
  "output": {
    "ranges": [
      {
        "range": "text/html",
        "quality": 1,
        "parameters": []
      },
      {
        "range": "application/json",
        "quality": 0.8,
        "parameters": []
      },
      {
        "range": "*/*",
        "quality": 0.1,
        "parameters": []
      }
    ]
  }
}

Limitations and assumptions

No representation is selected and no specificity ranking or media-parameter/extension semantic separation is applied. Quoted q, duplicate q and invalid syntax fail.

Numeric inputs must be finite. Follow the calculation-specific rules for overflow, underflow and exceptional cases. Extremely large text inputs are rejected. Missing required fields, extra fields, wrong value types and violations of the calculation rules are input errors.

Alternative or Complementary methods

Use HTTP Accept-Language Parser: Parse RFC 4647 basic language ranges and HTTP quality weights while retaining header order. For a complementary task, use HTTP Content-Type Parser: Parse an HTTP media type and its parameters, preserving parameter values and rejecting duplicate names.

Further background: RFC 9110: Accept.

References

  1. HTTP Accept Parser — tool.io

  2. RFC 9110: Accept — HTTP Working Group

  3. HTTP Content-Type Parser — tool.io

Similar or alternative tools

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies