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
Copy file name to clipboardExpand all lines: src/oas.md
+66Lines changed: 66 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2524,6 +2524,72 @@ components:
2524
2524
$ref: '#/components/mediaTypes/CollectionLinks'
2525
2525
```
2526
2526
2527
+
##### Representing the `Set-Cookie` Header
2528
+
2529
+
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.
2530
+
2531
+
```http
2532
+
Set-Cookie: lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
2533
+
Set-Cookie: foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
2534
+
```
2535
+
2536
+
If these values were to be place 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`.
2537
+
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.
2538
+
2539
+
RFC9110 therefore advises recipients to 'handle "Set-Cookie" as a special case while processing fields,' so the OAS similarly special-cases its handling of `Set-Cookie` as follows:
2540
+
2541
+
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.
2542
+
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.
2543
+
2544
+
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:
2545
+
2546
+
```yaml
2547
+
components:
2548
+
headers:
2549
+
SetCookieWithExpires:
2550
+
# Spaces within the Expires values prevent the use of `schema` and
2551
+
# `style` as they would be percent-encoded, even with `allowReserved`.
2552
+
content:
2553
+
text/plain:
2554
+
schema:
2555
+
type: string
2556
+
allOf:
2557
+
- pattern: "^lang=[^;];.*Expires="
2558
+
- pattern: "^foo=[^;];.*Expires="
2559
+
examples:
2560
+
WithExpires:
2561
+
# This demonstrates that the text is required to be provided
2562
+
# in the final format, and is not changed by serialization.
2563
+
# In practice, it is not necessary to show both fields here.
2564
+
dataValue: |
2565
+
lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
2566
+
foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
2567
+
serializedValue: |
2568
+
lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
2569
+
foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
2570
+
SetCookieWithNoSpaces:
2571
+
schema:
2572
+
type: object
2573
+
required:
2574
+
- lang
2575
+
- foo
2576
+
additionalProperties:
2577
+
type: string
2578
+
pattern: "^[^[:space:]]$"
2579
+
style: simple
2580
+
explode: true
2581
+
allowReserved: true # "=", ";", and " " are reserved
0 commit comments