Skip to content

Commit cb39927

Browse files
committed
Revamp with more examples and less explanation
Explain when Set-Cookie workaround is needed Also remove a stray line from an example that didn't really hurt but wasn't needed and could have been confusing.
1 parent 120b1d5 commit cb39927

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/oas.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,24 +2453,27 @@ Using `content` with a `text/plain` media type is RECOMMENDED for headers where
24532453

24542454
##### Representing the `Set-Cookie` Header
24552455

2456-
As noted in [[!RFC9110]] [Section 5.3](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.3) the `Set-Cookie` response header violates the requirements for representing multiple values as a comma-separated list, as `style: "simple"` produces.
2456+
The `Set-Cookie` header is noted in [[!RFC9110]] [Section 5.3](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.3) as an exception to the normal rules of headers with multiple values.
2457+
2458+
For most headers using the general syntax defined in RFC9110, the multiple-line and comma-separaed single-line forms are interchangeable, meaning that this:
24572459

24582460
```http
2459-
Set-Cookie: lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
2460-
Set-Cookie: foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
2461+
Accept-Encoding: compress;q=0.5
2462+
Accept-Encoding: gzip;q=1.0
24612463
```
24622464

2463-
If these values were to be placed on a single line using `style: "simple"`, the result would be `lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT,foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT`, which when split would then produce four values: `lang=en-US; Expires=Wed`, `09 Jun 2021 10:18:14 GMT`, `foo=bar; Expires=Wed`, and `09 Jun 2021 10:18:14 GMT`.
2464-
While the two dates (`09...`) are not valid `Set-Cookie` values on their own, [[?RFC6265]] does not provide any guarantee that all such embedded uses of commas will produce detectable errors when split in this way.
2465+
is interchangeable with the one-line form that works well with the OAS's `style: "simple"` option:
24652466

2466-
RFC9110 therefore advises recipients to 'handle "Set-Cookie" as a special case while processing fields,' so the OAS similarly applies a special case to its handling of `Set-Cookie`.
2467+
```http
2468+
Accept-Encoding: compress;q=0.5,gzip;q=1.0
2469+
```
24672470

2468-
When an OAS implementation is mapping directly between the multi-`Set-Cookie:` header line format and an array representation, without any intermediate single string holding the multiple values, no special handling is needed as the behavior is the same as for headers that can be either on a single line with comma-separated values or on multiple lines.
2471+
The OAS models such multi-value headers using the one-line form as it matches the behavior of `style: "simple"`, and works well when using `content` as the values are completely separate from the header name, but it does not matter which form is used in an actual HTTP message.
24692472

2470-
However, if a multi-value text representation is needed, such as for a `text/plain` representation (using the `content` field) or in an Example Object, the following special handling is required:
2473+
As also noted in the RFC, `Set-Cookie` is an exception as it allows unquoted, non-escaped commas in its values, and can only use the one-value-per-line form.
2474+
For HTTP messages, this is purely a serialization concern, and no more of a problem than a message that uses the multi-line form of any other header.
24712475

2472-
For the `Set-Cookie` response header _**only**_, `style: "simple"` MUST be treated as producing a newline-delimited list instead of a comma-separated list, with each line corresponding to the value of a single `Set-Cookie:` header field.
2473-
This newline-delimited format MUST be used whenever a string representing the values is required, including in the [Example Object's](#example-object) serialized example fields, and when using `content` with a `text/plain` [Media Type Object](#media-type-object) as is necessary to prevent percent-encoding whitespace.
2476+
However, because examples and values modeled with `content` do not incorporate the header name, for these fields `Set-Cookie` MUST be handled by placing each value on a separate line, without the header name or the `:` delimiter.
24742477

24752478
The following example shows two different ways to describe `Set-Cookie` headers that require cookies named `"lang"` and `"foo"`. The first uses `content` to preserve the necessary whitespace in the `"Expires"` cookie attribute, while the second shows the use of `style: "simple"` and forbids whitespace to ensure that values work with this serialization approach:
24762479

@@ -2491,7 +2494,7 @@ components:
24912494
WithExpires:
24922495
# This demonstrates that the text is required to be provided
24932496
# in the final format, and is not changed by serialization.
2494-
# In practice, it is not necessary to show both fields here.
2497+
# In practice, it is not necessary to show both value fields.
24952498
dataValue: |
24962499
lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
24972500
foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
@@ -2520,6 +2523,20 @@ components:
25202523
foo=bar
25212524
```
25222525
2526+
In an HTTP message, the serialized example with Expires would look like:
2527+
2528+
```http
2529+
Set-Cookie: lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GM
2530+
Set-Cookie: foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
2531+
```
2532+
2533+
and the example without Expires would look like:
2534+
2535+
```http
2536+
Set-Cookie: lang=en-US
2537+
Set-Cookie: foo=bar
2538+
```
2539+
25232540
##### Header Object Example
25242541
25252542
A simple header of type `integer`:

0 commit comments

Comments
 (0)