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
Changes to our understanding of percent-encoding and headers
have made the previous example incorrect. This brings it into
agreement with the new recommendations.
This also explains how percent-encoding and other escaping is
handled, and links to the updated Appendix D which provids more
detail including a link to the IETF draft update of the cookie
RFC that clarifies this.
Copy file name to clipboardExpand all lines: src/oas.md
+21-19Lines changed: 21 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3036,14 +3036,14 @@ For HTTP messages, this is purely a serialization concern, and no more of a prob
3036
3036
3037
3037
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.
3038
3038
3039
-
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:
3039
+
Note also that any URI percent-encoding, base64 encoding, or other escaping MUST be performed prior to supplying the data to OAS tooling; see [Appendix D](appendix-d-serializing-headers-and-cookies) for details.
3040
+
3041
+
The following example shows two different ways to describe `Set-Cookie` headers that require cookies named `"lang"` and `"foo"`, as well as a `"urlSafeData"` cookie that is expected to be percent-encoded. The first uses `content` in order to show exactly how such examples are formatted, but also notes the limitations of schema constraints with multi-line text. The second shows the use of `style: "simple"`, which produces the same serialized example text (with each line corresponding to one `Set-Cookie:` line in the HTTP response), but allows schema constraints on each cookie; note that the percent-encoding is already applied in the `dataValue` field of the example:
3040
3042
3041
3043
```yaml
3042
3044
components:
3043
3045
headers:
3044
-
SetCookieWithExpires:
3045
-
# Spaces within the Expires values prevent the use of `schema` and
3046
-
# `style` as they would be percent-encoded, even with `allowReserved`.
3046
+
SetCookieWithContent:
3047
3047
content:
3048
3048
text/plain:
3049
3049
schema:
@@ -3058,45 +3058,47 @@ components:
3058
3058
dataValue: |
3059
3059
lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3060
3060
foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3061
+
urlSafeData: Hello%2C%20world%21
3061
3062
serializedValue: |
3062
3063
lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3063
3064
foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3064
-
SetCookieWithNoSpaces:
3065
+
urlSafeData: Hello%2C%20world%21
3066
+
SetCookieWithSchemaAnd Style:
3065
3067
schema:
3066
3068
type: object
3067
3069
required:
3068
3070
- lang
3069
3071
- foo
3072
+
- urlSafeData
3073
+
properties:
3074
+
urlSafeData:
3075
+
type: string
3076
+
pattern: ^[-_.%a-zA-Z0-9]+(;|$)
3070
3077
additionalProperties:
3071
-
type: string
3072
-
pattern: "^[^[:space:]]*$"
3078
+
# Require an Expires parameter
3079
+
pattern: "; *Expires="
3073
3080
style: simple
3074
3081
explode: true
3075
3082
examples:
3076
3083
SetCookies:
3077
3084
dataValue: {
3078
-
"lang": "en-US",
3079
-
"foo": "bar"
3085
+
"lang": "en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT"
3086
+
"foo": "bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT"
3087
+
"urlSafeData": "Hello%2C%20world%21"
3080
3088
}
3081
3089
serializedValue: |
3082
-
lang=en-US
3083
-
foo=bar
3090
+
lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3091
+
foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3092
+
urlSafeData: Hello%2C%20world%21
3084
3093
```
3085
3094
3086
-
In an HTTP message, the serialized example with Expires would look like:
3095
+
In an HTTP message, the serialized example would look like:
3087
3096
3088
3097
```http
3089
3098
Set-Cookie: lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GM
3090
3099
Set-Cookie: foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
0 commit comments