HTTP Cookie Parser

Parse a Cookie header into ordered name and value pairs while preserving duplicate cookie names and encoded values.

Description

A request Cookie header contains ordered name/value pairs.

A request Cookie header contains ordered name/value pairs. Repeated names can arise, so collapsing them to an object can lose information.1, 2

The returned values include Cookie pairs in source order. The How section below explains the calculation, input rules and interpretation.

When to use HTTP Cookie Parser

Use HTTP Cookie Parser when you need to evaluate the supplied records under the calculation and evidence rules below. No Set-Cookie attributes, expiry, cookie-store policy, URL decoding or authentication is evaluated. Trailing semicolons and malformed pairs are errors.

Paste the requested HTTP header field value. Use the field table to distinguish request cookies, media types and authorization credentials.

How to use HTTP Cookie Parser and understand its results

  1. Paste the requested HTTP header field value. Use the field table to distinguish request cookies, media types and authorization credentials.
  2. Enter header using the field table and calculation rules, then run the tool.
  3. Read cookies. 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
headerCookie field value.string; maximum length: 1000000Required

Paste only the field value. Blank input returns an empty list. Reject control characters; split on semicolons and each pair's first equals sign. Trim name/value, remove matched outer double quotes and validate ASCII token names/cookie-octet values. Preserve duplicates, case, further equals signs and percent encoding.

cookies=semicolon-separated valid pairs in source order

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

Output fieldMeaningValue type
cookiesCookie pairs in source order.list of object; minimum entries: 0; maximum entries: 100000
cookies[].nameField in cookies recordstring; maximum length: 1000000
cookies[].valueField in cookies recordstring; maximum length: 1000000
json
{
  "input": {
    "header": "session=abc%20123; theme=dark; session=second"
  },
  "output": {
    "cookies": [
      {
        "name": "session",
        "value": "abc%20123"
      },
      {
        "name": "theme",
        "value": "dark"
      },
      {
        "name": "session",
        "value": "second"
      }
    ]
  }
}

Limitations and assumptions

No Set-Cookie attributes, expiry, cookie-store policy, URL decoding or authentication is evaluated. Trailing semicolons and malformed pairs are errors.

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

Alternative or Complementary methods

Use HTTP Set-Cookie Parser: Parse one Set-Cookie field into its cookie pair and ordered attributes, preserving extensions and Expires text. For a complementary task, use HTTP Content-Type Parser: A Content-Type field identifies a media type plus optional parameters such as charset or boundary. Parameter name normalization must not alter parameter values.

Further background: RFC 6265: HTTP State Management Mechanism.

References

  1. HTTP Cookie Parser — tool.io

  2. RFC 6265: HTTP State Management Mechanism — IETF

Similar or alternative tools

  • HTTP Set-Cookie Parser

    Parse one Set-Cookie field into its cookie pair and ordered attributes, preserving extensions and Expires text.

  • HTTP Content-Type Parser

    A Content-Type field identifies a media type plus optional parameters such as charset or boundary. Parameter name normalization must not alter parameter values.

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