HTTP Set-Cookie Serializer

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

Description

Set-Cookie sends one cookie pair from server to client with optional attributes.

Set-Cookie sends one cookie pair from server to client with optional attributes. An empty attribute value is rendered as a flag such as Secure.1, 2

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

When to use HTTP Set-Cookie Serializer

Use this tool to serialize one cookie pair and explicit attributes while rejecting characters that can create additional header fields.

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 Serializer 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 name, value, attributes using the field table and calculation rules, then run the tool.
  3. Read header. 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
nameCookie name.string; maximum length: 1000000Required
valueCookie value.string; maximum length: 1000000Required
attributesCookie attributes; an empty value emits a flag.list of object; minimum entries: 0; maximum entries: 100000Required

Enter a nonempty ASCII token name, valid cookie value and ordered attribute objects with name/value fields. Cookie values may be empty but reject whitespace, quotation marks, comma, semicolon, backslash, controls and non-ASCII. Attribute names are tokens; values allow printable ASCII except semicolon. Return one header field value; preserve attribute spelling, order and duplicates.3

header=name=value + ordered ; attribute[=value] fragments

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

Output fieldMeaningValue type
headerSerialized Set-Cookie field value.string; maximum length: 1000000
json
{
  "input": {
    "name": "theme",
    "value": "dark",
    "attributes": [
      {
        "name": "Path",
        "value": "/"
      },
      {
        "name": "Secure",
        "value": ""
      }
    ]
  },
  "output": {
    "header": "theme=dark; Path=/; Secure"
  }
}

Limitations and assumptions

No escaping, encoding, cookie storage or attribute semantics are supplied. Expires, SameSite, domain/path and prefix rules require separate validation.

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 Parser: Parse one Set-Cookie field into its cookie pair and ordered attributes, preserving extensions and Expires text. For a complementary task, use HTTP Cookie Serializer: Serialize ordered cookie pairs using RFC 6265 cookie octets without implicit escaping or decoding.

Further background: RFC 6265: HTTP State Management Mechanism.

References

  1. HTTP Set-Cookie Serializer — tool.io

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

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 Cookie Serializer

    Serialize ordered cookie pairs using RFC 6265 cookie octets without implicit escaping or decoding.

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