Random HTTP Content Negotiation Exercise Generator

Build reproducible Accept-header negotiation cards with imported parsing and explicit parameter-free offered media types. Most-specific range determines each quality; zero-quality offers excluded and best-quality ties retained. Conflicting duplicate qualities or media parameters/extensions fail this bounded submodel rather than infer precedence. Uniform caller candidate-position sampling with explicit replacement; not a full HTTP server negotiation or precondition implementation.

Description

The HTTP Accept field expresses media ranges and quality weights that can be compared with offered representations.

The HTTP Accept field expresses media ranges and quality weights that can be compared with offered representations.1, 2

These exercises combine sampled headers with supplied parameter-free offered media types, assigning quality from each offer’s most specific matching range and retaining every best positive-quality tie.

When to use Random HTTP Content Negotiation Exercise Generator

Use this tool when you need to assemble reproducible practice cards from a supplied, validated scenario corpus. Prepare a reproducible seed and the inventory, corpus, or experiment parameters stated below.

How to use Random HTTP Content Negotiation Exercise Generator and understand its results

  1. Prepare a reproducible seed and the inventory, corpus, or experiment parameters stated below.
  2. Enter seed, count, withoutReplacement, candidateInputsJson, offeredMediaTypes, following the field table and calculation rules below, then run the tool.
  3. Read result. For result objects, inspect the nested output fields below, including any missing evidence or selected indices.
  4. Correct any input issues and run again. Before using a successful result, review its units, signs, evidence coverage, and stated model or reference assumptions.
Input fieldMeaningValue typeRequirement
seedRequired nonblank deterministic seed; the SDK can replace the source with context.random.stringRequired
countNumber of draws, cards, trials, or output entries under the tool-specific rule; safe integer 1–64 with any narrower inventory bound.numberRequired
withoutReplacementTrue removes selected inventory positions; false permits repeated positions. Equal rendered values or answers can still occur.booleanRequired
candidateInputsJsonDense list of JSON objects serialized as strings for the imported calculator; every candidate must be valid.list of stringRequired
offeredMediaTypesUnique after case folding, literal parameter-free type/subtype offers; their input positions identify the best-offer indices.list of stringRequired

Enter 1–128 dense candidateInputsJson strings, each a strict JSON object for the imported calculator. Each string is at most 8192 UTF-16 units, the corpus at most 131072, and nesting at most 16 levels; nonfinite numbers and prototype-control keys are rejected. Select candidate positions under the sampling rules, then validate every candidate, including undrawn ones, by invoking the imported calculator with a fixed random source of 0.5. Any invalid candidate fails the whole request. Invoke it again for selected candidates with the request’s advancing source, and return original inputs, actual answer objects, selected indices, and never-selected indices. Duplicate candidate texts or equal answers may occur at distinct positions.3, 4, 5, 6

Use a nonblank seed of at most 256 UTF-16 units and a safe-integer count from 1 to 64, subject to the tool’s narrower inventory bound. By default the seed is hashed into a deterministic pseudorandom state; each run restarts that state, so identical full inputs and implementation reproduce the result. The SDK may provide context.random, which replaces the seeded source and advances across the request; the seed remains required. Every source value must be finite in [0,1), with a request limit of 100000 source calls. Draw an index as floor(U×remainingSize). For indexed inventory draws, with replacement draw from the full inventory each time; without replacement remove each chosen position from an ordered pool and reject counts exceeding the inventory size. Uniform-source draws are over positions, not necessarily distinct values. This is not secure randomness.

The imported parser splits media ranges outside quoted delimiters, lowercases each range, validates wildcard structure, and preserves non-q parameters. Quality defaults to one; an explicit unquoted q must be zero to one with at most three decimal digits and cannot repeat. The parser returns source order; the additional exercise matching step is described below.

Supply unique parameter-free offeredMediaTypes after case folding, with literal type/subtype tokens and no wildcards. The imported parser produces media ranges and quality values as described above. For each selected card, reject media parameters and accept extensions; these additional exercise restrictions are checked on selected cards, while every candidate is checked by the imported parser. For each offer prefer an exact match over type/* over */*, then use that specificity’s quality. No match gives zero. Conflicting qualities on equally specific duplicate matching ranges fail rather than silently choosing a precedence. Return negotiation.offeredMediaTypes in their original input spelling, aligned qualities, and every zero-based bestOfferIndices whose quality is positive and equals the maximum. All-zero quality returns an empty best list. This is a bounded negotiation exercise, not a complete server policy.

quality(offer)=qualityOfMostSpecificMatchingRange or 0; bestIndices={i:q_i>0 and q_i=max(q)}

Read these symbols with the field meanings and branch or reference rules above.

Output fieldMeaningValue type
resultComposite output; read its nested fields and the worked example.object
result.baseToolIdCanonical identifier of the imported answer calculator.string
result.selectedCandidateIndicesZero-based positions in the original candidate corpus, in draw order.list
result.unusedCandidateIndicesOriginal candidate positions never selected during this request.list
result.exercisesSelected supplied input objects paired with their actual imported answer objects and any stated additional outputs.list

Each result.exercises entry preserves its supplied input and imported answer object. Additional roundTripAnswer, secondaryAnswer, prompts, or derived quantities appear only where the mechanics above describe them. selectedCandidateIndices and unusedCandidateIndices refer to the original corpus positions, not answer values.

json
{
  "input": {
    "seed": "tool.io/batch42",
    "count": 1,
    "withoutReplacement": true,
    "candidateInputsJson": [
      "{\"header\": \"text/html; q=0.8, application/json; q=1\"}"
    ],
    "offeredMediaTypes": [
      "text/html",
      "application/json"
    ]
  },
  "output": {
    "result": {
      "baseToolId": "http/accept-parser",
      "selectedCandidateIndices": [
        0
      ],
      "unusedCandidateIndices": [],
      "exercises": [
        {
          "input": {
            "header": "text/html; q=0.8, application/json; q=1"
          },
          "answer": {
            "ranges": [
              {
                "range": "text/html",
                "quality": 0.8,
                "parameters": []
              },
              {
                "range": "application/json",
                "quality": 1,
                "parameters": []
              }
            ]
          },
          "negotiation": {
            "offeredMediaTypes": [
              "text/html",
              "application/json"
            ],
            "qualities": [
              0.8,
              1
            ],
            "bestOfferIndices": [
              1
            ]
          }
        }
      ]
    }
  }
}

Limitations and assumptions

Only parameter-free offers and selected Accept ranges without media parameters or extensions are supported. Most-specific quality precedence is explicit, equally specific conflicts fail, and best offers remain tied rather than selecting a server winner. No HTTP requests or server representation choices occur.

Missing required fields, unknown fields, wrong types, and violated calculation rules return input issues. Numeric values must be finite; nonfinite numeric outputs are rejected. Arrays must be dense, with no missing cells. Ordinary string lists allow at most 128 strings of at most 128 UTF-16 units each. Extremely large composite outputs are rejected.

Alternative or Complementary methods

For a related task, use Random HTTP Status Classification Quiz Generator: HTTP response status codes are grouped by their leading digit into five broad classes. This quiz samples supplied codes and classifies their numeric range, without checking whether a specific code is registered. For a complementary step, use Random HTTP Content-Disposition Corpus Generator: Content-Disposition describes how a representation may be presented and can carry a filename parameter. These fixtures parse supplied field values, keeping extended parameter values available for separate interpretation.

References

  1. Random HTTP Content Negotiation Exercise Generator — tool.io

  2. RFC 9110: HTTP Semantics — IETF

  3. HTTP Accept Parser — tool.io

  4. Calculation or validation: random/seeded-number — tool.io

  5. Calculation or validation: random/number — tool.io

  6. HTTP Content-Type Parser — tool.io

Similar or alternative tools

  • Random HTTP Status Classification Quiz Generator

    HTTP response status codes are grouped by their leading digit into five broad classes. This quiz samples supplied codes and classifies their numeric range, without checking whether a specific code is registered.

  • Random HTTP Content-Disposition Corpus Generator

    Content-Disposition describes how a representation may be presented and can carry a filename parameter. These fixtures parse supplied field values, keeping extended parameter values available for separate interpretation.

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