HTTP Set-Cookie Parser

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

Description

A Set-Cookie field carries one cookie pair and attribute parameters.

A Set-Cookie field carries one cookie pair and attribute parameters. Expires can contain a comma, so separate fields should be supplied individually.1, 2

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

When to use HTTP Set-Cookie Parser

Use this tool to parse one Set-Cookie field into its cookie pair and ordered attributes, preserving extensions and Expires text.

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 Set-Cookie 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 name, value, attributes. 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
headerOne Set-Cookie field value; combined fields are not supported.string; maximum length: 1000000Required

Paste one field value. Reject CR, LF and NUL; parse the first equals sign, trim name/value and remove matching surrounding double quotes from the cookie value. Validate cookie octets. Trim attributes, lowercase names and retain values/order/duplicates; flag attributes have empty values. Return name, value and attributes.3

split on semicolons; first part=cookie pair; remaining parts=attributes

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

Output fieldMeaningValue type
nameCookie name.string; maximum length: 1000000
valueCookie value.string; maximum length: 1000000
attributesAttributes with lowercase names and empty values for flags.list of object; minimum entries: 0; maximum entries: 100000
json
{
  "input": {
    "header": "session=abc; Path=/; Secure; HttpOnly; SameSite=Lax"
  },
  "output": {
    "name": "session",
    "value": "abc",
    "attributes": [
      {
        "name": "path",
        "value": "/"
      },
      {
        "name": "secure",
        "value": ""
      },
      {
        "name": "httponly",
        "value": ""
      },
      {
        "name": "samesite",
        "value": "Lax"
      }
    ]
  }
}

Limitations and assumptions

No percent-decoding, browser acceptance, expiration-date parsing or cookie policy is assessed. Combined Set-Cookie fields are unsupported, and a trailing empty attribute fails.

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 Set-Cookie Serializer: Serialize one cookie pair and explicit attributes while rejecting characters that can create additional header fields. For a complementary task, use HTTP Cookie Parser: Parse a Cookie header into ordered name and value pairs while preserving duplicate cookie names and encoded values.

Further background: RFC 6265: HTTP State Management Mechanism.

References

  1. HTTP Set-Cookie Parser — tool.io

  2. RFC 6265: HTTP State Management Mechanism — Internet Engineering Task Force

Similar or alternative tools

  • HTTP Set-Cookie Serializer

    Serialize one cookie pair and explicit attributes while rejecting characters that can create additional header fields.

  • HTTP Cookie Parser

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

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