You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: src/oas.md
+28-11Lines changed: 28 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -2453,24 +2453,27 @@ Using `content` with a `text/plain` media type is RECOMMENDED for headers where
2453
2453
2454
2454
##### Representing the `Set-Cookie` Header
2455
2455
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:
2457
2459
2458
2460
```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
2461
2463
```
2462
2464
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:
2465
2466
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
+
```
2467
2470
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.
2469
2472
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.
2471
2475
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.
2474
2477
2475
2478
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:
2476
2479
@@ -2491,7 +2494,7 @@ components:
2491
2494
WithExpires:
2492
2495
# This demonstrates that the text is required to be provided
2493
2496
# 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.
2495
2498
dataValue: |
2496
2499
lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
2497
2500
foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
@@ -2520,6 +2523,20 @@ components:
2520
2523
foo=bar
2521
2524
```
2522
2525
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
0 commit comments