idnits 2.17.1 draft-ietf-httpbis-header-structure-17.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The abstract seems to contain references ([2], [3], [4], [5], [1]), which it shouldn't. Please replace those with straight textual mentions of the documents in question. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (March 15, 2020) is 1495 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Looks like a reference, but probably isn't: '1' on line 1567 -- Looks like a reference, but probably isn't: '2' on line 1569 -- Looks like a reference, but probably isn't: '3' on line 1571 -- Looks like a reference, but probably isn't: '4' on line 1573 -- Looks like a reference, but probably isn't: '5' on line 1575 == Missing Reference: 'RFCxxxx' is mentioned on line 331, but not defined == Missing Reference: 'RFC3986' is mentioned on line 337, but not defined -- Looks like a reference, but probably isn't: '6' on line 1628 ** Obsolete normative reference: RFC 7230 (Obsoleted by RFC 9110, RFC 9112) -- Obsolete informational reference (is this intentional?): RFC 7231 (Obsoleted by RFC 9110) -- Obsolete informational reference (is this intentional?): RFC 7540 (Obsoleted by RFC 9113) Summary: 2 errors (**), 0 flaws (~~), 3 warnings (==), 9 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 HTTP M. Nottingham 3 Internet-Draft Fastly 4 Intended status: Standards Track P-H. Kamp 5 Expires: September 16, 2020 The Varnish Cache Project 6 March 15, 2020 8 Structured Field Values for HTTP 9 draft-ietf-httpbis-header-structure-17 11 Abstract 13 This document describes a set of data types and associated algorithms 14 that are intended to make it easier and safer to define and handle 15 HTTP header and trailer fields, known as "Structured Fields", or 16 "Structured Headers". It is intended for use by specifications of 17 new HTTP fields that wish to use a common syntax that is more 18 restrictive than traditional HTTP field values. 20 Note to Readers 22 _RFC EDITOR: please remove this section before publication_ 24 Discussion of this draft takes place on the HTTP working group 25 mailing list (ietf-http-wg@w3.org), which is archived at 26 https://lists.w3.org/Archives/Public/ietf-http-wg/ [1]. 28 Working Group information can be found at https://httpwg.github.io/ 29 [2]; source code and issues list for this draft can be found at 30 https://github.com/httpwg/http-extensions/labels/header-structure 31 [3]. 33 Tests for implementations are collected at https://github.com/httpwg/ 34 structured-header-tests [4]. 36 Implementations are tracked at https://github.com/httpwg/wiki/wiki/ 37 Structured-Headers [5]. 39 Status of This Memo 41 This Internet-Draft is submitted in full conformance with the 42 provisions of BCP 78 and BCP 79. 44 Internet-Drafts are working documents of the Internet Engineering 45 Task Force (IETF). Note that other groups may also distribute 46 working documents as Internet-Drafts. The list of current Internet- 47 Drafts is at https://datatracker.ietf.org/drafts/current/. 49 Internet-Drafts are draft documents valid for a maximum of six months 50 and may be updated, replaced, or obsoleted by other documents at any 51 time. It is inappropriate to use Internet-Drafts as reference 52 material or to cite them other than as "work in progress." 54 This Internet-Draft will expire on September 16, 2020. 56 Copyright Notice 58 Copyright (c) 2020 IETF Trust and the persons identified as the 59 document authors. All rights reserved. 61 This document is subject to BCP 78 and the IETF Trust's Legal 62 Provisions Relating to IETF Documents 63 (https://trustee.ietf.org/license-info) in effect on the date of 64 publication of this document. Please review these documents 65 carefully, as they describe your rights and restrictions with respect 66 to this document. Code Components extracted from this document must 67 include Simplified BSD License text as described in Section 4.e of 68 the Trust Legal Provisions and are provided without warranty as 69 described in the Simplified BSD License. 71 Table of Contents 73 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 74 1.1. Intentionally Strict Processing . . . . . . . . . . . . . 4 75 1.2. Notational Conventions . . . . . . . . . . . . . . . . . 5 76 2. Defining New Structured Fields . . . . . . . . . . . . . . . 5 77 3. Structured Data Types . . . . . . . . . . . . . . . . . . . . 8 78 3.1. Lists . . . . . . . . . . . . . . . . . . . . . . . . . . 9 79 3.1.1. Inner Lists . . . . . . . . . . . . . . . . . . . . . 9 80 3.1.2. Parameters . . . . . . . . . . . . . . . . . . . . . 10 81 3.2. Dictionaries . . . . . . . . . . . . . . . . . . . . . . 11 82 3.3. Items . . . . . . . . . . . . . . . . . . . . . . . . . . 12 83 3.3.1. Integers . . . . . . . . . . . . . . . . . . . . . . 13 84 3.3.2. Decimals . . . . . . . . . . . . . . . . . . . . . . 13 85 3.3.3. Strings . . . . . . . . . . . . . . . . . . . . . . . 13 86 3.3.4. Tokens . . . . . . . . . . . . . . . . . . . . . . . 14 87 3.3.5. Byte Sequences . . . . . . . . . . . . . . . . . . . 14 88 3.3.6. Booleans . . . . . . . . . . . . . . . . . . . . . . 15 89 4. Working With Structured Fields in HTTP . . . . . . . . . . . 15 90 4.1. Serializing Structured Fields . . . . . . . . . . . . . . 15 91 4.1.1. Serializing a List . . . . . . . . . . . . . . . . . 16 92 4.1.2. Serializing a Dictionary . . . . . . . . . . . . . . 18 93 4.1.3. Serializing an Item . . . . . . . . . . . . . . . . . 18 94 4.1.4. Serializing an Integer . . . . . . . . . . . . . . . 19 95 4.1.5. Serializing a Decimal . . . . . . . . . . . . . . . . 20 96 4.1.6. Serializing a String . . . . . . . . . . . . . . . . 20 97 4.1.7. Serializing a Token . . . . . . . . . . . . . . . . . 21 98 4.1.8. Serializing a Byte Sequence . . . . . . . . . . . . . 21 99 4.1.9. Serializing a Boolean . . . . . . . . . . . . . . . . 22 100 4.2. Parsing Structured Fields . . . . . . . . . . . . . . . . 22 101 4.2.1. Parsing a List . . . . . . . . . . . . . . . . . . . 24 102 4.2.2. Parsing a Dictionary . . . . . . . . . . . . . . . . 25 103 4.2.3. Parsing an Item . . . . . . . . . . . . . . . . . . . 26 104 4.2.4. Parsing an Integer or Decimal . . . . . . . . . . . . 28 105 4.2.5. Parsing a String . . . . . . . . . . . . . . . . . . 30 106 4.2.6. Parsing a Token . . . . . . . . . . . . . . . . . . . 30 107 4.2.7. Parsing a Byte Sequence . . . . . . . . . . . . . . . 31 108 4.2.8. Parsing a Boolean . . . . . . . . . . . . . . . . . . 32 109 5. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 32 110 6. Security Considerations . . . . . . . . . . . . . . . . . . . 32 111 7. References . . . . . . . . . . . . . . . . . . . . . . . . . 32 112 7.1. Normative References . . . . . . . . . . . . . . . . . . 32 113 7.2. Informative References . . . . . . . . . . . . . . . . . 33 114 7.3. URIs . . . . . . . . . . . . . . . . . . . . . . . . . . 34 115 Appendix A. Frequently Asked Questions . . . . . . . . . . . . . 34 116 A.1. Why not JSON? . . . . . . . . . . . . . . . . . . . . . . 34 117 Appendix B. Implementation Notes . . . . . . . . . . . . . . . . 35 118 Appendix C. Changes . . . . . . . . . . . . . . . . . . . . . . 35 119 C.1. Since draft-ietf-httpbis-header-structure-15 . . . . . . 36 120 C.2. Since draft-ietf-httpbis-header-structure-14 . . . . . . 36 121 C.3. Since draft-ietf-httpbis-header-structure-13 . . . . . . 37 122 C.4. Since draft-ietf-httpbis-header-structure-12 . . . . . . 37 123 C.5. Since draft-ietf-httpbis-header-structure-11 . . . . . . 37 124 C.6. Since draft-ietf-httpbis-header-structure-10 . . . . . . 37 125 C.7. Since draft-ietf-httpbis-header-structure-09 . . . . . . 38 126 C.8. Since draft-ietf-httpbis-header-structure-08 . . . . . . 38 127 C.9. Since draft-ietf-httpbis-header-structure-07 . . . . . . 38 128 C.10. Since draft-ietf-httpbis-header-structure-06 . . . . . . 39 129 C.11. Since draft-ietf-httpbis-header-structure-05 . . . . . . 39 130 C.12. Since draft-ietf-httpbis-header-structure-04 . . . . . . 39 131 C.13. Since draft-ietf-httpbis-header-structure-03 . . . . . . 39 132 C.14. Since draft-ietf-httpbis-header-structure-02 . . . . . . 39 133 C.15. Since draft-ietf-httpbis-header-structure-01 . . . . . . 40 134 C.16. Since draft-ietf-httpbis-header-structure-00 . . . . . . 40 135 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 40 136 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 40 138 1. Introduction 140 Specifying the syntax of new HTTP header (and trailer) fields is an 141 onerous task; even with the guidance in Section 8.3.1 of [RFC7231], 142 there are many decisions - and pitfalls - for a prospective HTTP 143 field author. 145 Once a field is defined, bespoke parsers and serializers often need 146 to be written, because each field value has slightly different 147 handling of what looks like common syntax. 149 This document introduces a set of common data structures for use in 150 definitions of new HTTP field values to address these problems. In 151 particular, it defines a generic, abstract model for them, along with 152 a concrete serialization for expressing that model in HTTP [RFC7230] 153 header and trailer fields. 155 A HTTP field that is defined as a "Structured Header" (or "Structured 156 Trailer", respectively; if the field can be either, it is a 157 "Structured Field") uses the types defined in this specification to 158 define its syntax and basic handling rules, thereby simplifying both 159 its definition by specification writers and handling by 160 implementations. 162 Additionally, future versions of HTTP can define alternative 163 serializations of the abstract model of these structures, allowing 164 fields that use it to be transmitted more efficiently without being 165 redefined. 167 Note that it is not a goal of this document to redefine the syntax of 168 existing HTTP fields; the mechanisms described herein are only 169 intended to be used with those that explicitly opt into them. 171 Section 2 describes how to specify a Structured Field. 173 Section 3 defines a number of abstract data types that can be used in 174 Structured Fields. 176 Those abstract types can be serialized into and parsed from HTTP 177 field values using the algorithms described in Section 4. 179 1.1. Intentionally Strict Processing 181 This specification intentionally defines strict parsing and 182 serialization behaviors using step-by-step algorithms; the only error 183 handling defined is to fail the operation altogether. 185 It is designed to encourage faithful implementation and therefore 186 good interoperability. Therefore, an implementation that tried to be 187 "helpful" by being more tolerant of input would make interoperability 188 worse, since that would create pressure on other implementations to 189 implement similar (but likely subtly different) workarounds. 191 In other words, strict processing is an intentional feature of this 192 specification; it allows non-conformant input to be discovered and 193 corrected by the producer early, and avoids both interoperability and 194 security issues that might otherwise result. 196 Note that as a result of this strictness, if a field is appended to 197 by multiple parties (e.g., intermediaries, or different components in 198 the sender), an error in one party's value is likely to cause the 199 entire field value to fail parsing. 201 1.2. Notational Conventions 203 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 204 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 205 "OPTIONAL" in this document are to be interpreted as described in BCP 206 14 [RFC2119] [RFC8174] when, and only when, they appear in all 207 capitals, as shown here. 209 This document uses algorithms to specify parsing and serialization 210 behaviors, and the Augmented Backus-Naur Form (ABNF) notation of 211 [RFC5234] to illustrate expected syntax in HTTP header fields. In 212 doing so, it uses the VCHAR, SP, DIGIT, ALPHA and DQUOTE rules from 213 [RFC5234]. It also includes the tchar rule from [RFC7230]. 215 When parsing from HTTP fields, implementations MUST follow the 216 algorithms, but MAY vary in implementation so as the behaviors are 217 indistinguishable from specified behavior. If there is disagreement 218 between the parsing algorithms and ABNF, the specified algorithms 219 take precedence. In some places, the algorithms are "greedy" with 220 whitespace, but this should not affect conformance. 222 For serialization to HTTP fields, the ABNF illustrates the range of 223 acceptable wire representations with as much fidelity as possible, 224 and the algorithms define the recommended way to produce them. 225 Implementations MAY vary from the specified behavior so long as the 226 output still matches the ABNF. 228 2. Defining New Structured Fields 230 To specify a HTTP field as a Structured Field, its authors needs to: 232 o Reference this specification. Recipients and generators of the 233 field need to know that the requirements of this document are in 234 effect. 236 o Identify whether the field is a Structured Header (i.e., it can 237 only be used in the header section - the common case), a 238 Structured Field (only in the trailer section), or a Structured 239 Field (both). 241 o Specify the type of the field value; either List (Section 3.1), 242 Dictionary (Section 3.2), or Item (Section 3.3). 244 o Define the semantics of those structures. 246 o Specify any additional constraints upon the structures used, as 247 well as the consequences when those constraints are violated. 249 Typically, this means that a field definition will specify the top- 250 level type - List, Dictionary or Item - and then define its allowable 251 types, and constraints upon them. For example, a header defined as a 252 List might have all Integer members, or a mix of types; a header 253 defined as an Item might allow only Strings, and additionally only 254 strings beginning with the letter "Q". Likewise, Inner Lists are 255 only valid when a field definition explicitly allows them. 257 When parsing fails, the entire field is ignored (see Section 4.2); in 258 most situations, violating field-specific constraints should have the 259 same effect. Thus, if a header is defined as an Item and required to 260 be an Integer, but a String is received, the field will by default be 261 ignored. If the field requires different error handling, this should 262 be explicitly specified. 264 Both Items and Inner Lists allow parameters as an extensibility 265 mechanism; this means that values can later be extended to 266 accommodate more information, if need be. To preserve forward 267 compatibility, field specifications are discouraged from defining the 268 presence of an unrecognized Parameter as an error condition. 270 To further assure that this extensibility is available in the future, 271 and to encourage consumers to use a complete parser implementation, a 272 field definition can specify that "grease" Parameters be added by 273 senders. A specification could stipulate that all Parameters that 274 fit a defined pattern are reserved for this use and then encourage 275 them to be sent on some portion of requests. This helps to 276 discourage recipients from writing a parser that does not account for 277 Parameters. 279 Specifications that use Dictionaries can also allow for forward 280 compatibility by requiring that the presence of - as well as value 281 and type associated with - unknown members be ignored. Later 282 specifications can then add additional members, specifying 283 constraints on them as appropriate. 285 An extension to a structured field can then require that an entire 286 field value be ignored by a recipient that understands the extension 287 if constraints on the value it defines are not met. 289 A field definition cannot relax the requirements of this 290 specification because doing so would preclude handling by generic 291 software; they can only add additional constraints (for example, on 292 the numeric range of Integers and Decimals, the format of Strings and 293 Tokens, the types allowed in a Dictionary's values, or the number of 294 Items in a List). Likewise, field definitions can only use this 295 specification for the entire field value, not a portion thereof. 297 This specification defines minimums for the length or number of 298 various structures supported by implementations. It does not specify 299 maximum sizes in most cases, but authors should be aware that HTTP 300 implementations do impose various limits on the size of individual 301 fields, the total number of fields, and/or the size of the entire 302 header or trailer section. 304 Specifications can refer to a field name as a "structured header 305 name", "structured trailer name" or "structured field name" as 306 appropriate. Likewise, they can refer its field value as a 307 "structured header value", "structured trailer value" or "structured 308 field value" as necessary. Field definitions are encouraged to use 309 the ABNF rules beginning with "sh-" defined in this specification; 310 other rules in this specification are not intended for their use. 312 For example, a fictitious Foo-Example header field might be specified 313 as: 315 42. Foo-Example Header 317 The Foo-Example HTTP header field conveys information about how 318 much Foo the message has. 320 Foo-Example is a Item Structured Header [RFCxxxx]. Its value MUST be 321 an Integer (Section Y.Y of [RFCxxxx]). Its ABNF is: 323 Foo-Example = sh-integer 325 Its value indicates the amount of Foo in the message, and MUST 326 be between 0 and 10, inclusive; other values MUST cause 327 the entire header field to be ignored. 329 The following parameters are defined: 330 * A Parameter whose name is "foourl", and whose value is a String 331 (Section Y.Y of [RFCxxxx]), conveying the Foo URL 332 for the message. See below for processing requirements. 334 "foourl" contains a URI-reference (Section 4.1 of [RFC3986]). If 335 its value is not a valid URI-reference, the entire header field 336 MUST be ignored. If its value is a relative reference (Section 4.2 337 of [RFC3986]), it MUST be resolved (Section 5 of [RFC3986]) before 338 being used. 340 For example: 342 Foo-Example: 2; foourl="https://foo.example.com/" 344 3. Structured Data Types 346 This section defines the abstract value types that can be composed 347 into Structured Fields. The ABNF provided represents the on-wire 348 format in HTTP field values. 350 In summary: 352 o There are three top-level types that a HTTP field can be defined 353 as; Lists, Dictionaries, and Items. 355 o Lists and Dictionaries are containers; their members can be Items 356 or Inner Lists (which are themselves lists of items). 358 o Both Items and Inner Lists can be parameterized with key/value 359 pairs. 361 3.1. Lists 363 Lists are arrays of zero or more members, each of which can be an 364 Item (Section 3.3) or an Inner List (Section 3.1.1), both of which 365 can be Parameterized (Section 3.1.2). 367 The ABNF for Lists in HTTP fields is: 369 sh-list = list-member *( *SP "," *SP list-member ) 370 list-member = sh-item / inner-list 372 Each member is separated by a comma and optional whitespace. For 373 example, a field whose value is defined as a List of Strings could 374 look like: 376 Example-StrListHeader: "foo", "bar", "It was the best of times." 378 An empty List is denoted by not serializing the field at all. 380 Note that Lists can have their members split across multiple lines 381 inside a header or trailer section, as per Section 3.2.2 of 382 [RFC7230]; for example, the following are equivalent: 384 Example-Hdr: foo, bar 386 and 388 Example-Hdr: foo 389 Example-Hdr: bar 391 However, individual members of a List cannot be safely split between 392 across lines; see Section 4.2 for details. 394 Parsers MUST support Lists containing at least 1024 members. Field 395 specifications can constrain the types and cardinality of individual 396 List values as they require. 398 3.1.1. Inner Lists 400 An Inner List is an array of zero or more Items (Section 3.3). Both 401 the individual Items and the Inner List itself can be Parameterized 402 (Section 3.1.2). 404 The ABNF for Inner Lists is: 406 inner-list = "(" *SP [ sh-item *( 1*SP sh-item ) *SP ] ")" 407 parameters 409 Inner Lists are denoted by surrounding parenthesis, and have their 410 values delimited by a single space. A field whose value is defined 411 as a list of Inner Lists of Strings could look like: 413 Example-StrListListHeader: ("foo" "bar"), ("baz"), ("bat" "one"), () 415 Note that the last member in this example is an empty Inner List. 417 A header field whose value is defined as a list of Inner Lists with 418 Parameters at both levels could look like: 420 Example-ListListParam: ("foo"; a=1;b=2);lvl=5, ("bar" "baz");lvl=1 422 Parsers MUST support Inner Lists containing at least 256 members. 423 Field specifications can constrain the types and cardinality of 424 individual Inner List members as they require. 426 3.1.2. Parameters 428 Parameters are an ordered map of key-values pairs that are associated 429 with an Item (Section 3.3) or Inner List (Section 3.1.1). The keys 430 are unique within the scope the Parameters they occur within, and the 431 values are bare items (i.e., they themselves cannot be parameterized; 432 see Section 3.3). 434 The ABNF for Parameters is: 436 parameters = *( ";" *SP parameter ) 437 parameter = param-name [ "=" param-value ] 438 param-name = key 439 key = ( lcalpha / "*" ) 440 *( lcalpha / DIGIT / "_" / "-" / "." / "*" ) 441 lcalpha = %x61-7A ; a-z 442 param-value = bare-item 444 A parameter is separated from its Item or Inner List and other 445 parameters by a semicolon. For example: 447 Example-ParamListHeader: abc;a=1;b=2; cde_456, (ghi;jk=4 l);q="9";r=w 449 Parameters whose value is Boolean true MUST omit that value when 450 serialized. For example: 452 Example-IntHeader: 1; a; b=?0 454 Note that this requirement is only on serialization; parsers are 455 still required to correctly handle the true value when it appears in 456 a parameter. 458 Parsers MUST support at least 256 parameters on an Item or Inner 459 List, and support parameter keys with at least 64 characters. Field 460 specifications can constrain the types and cardinality of individual 461 parameter names and values as they require. 463 3.2. Dictionaries 465 Dictionaries are ordered maps of name-value pairs, where the names 466 are short, textual strings and the values are items (Section 3.3) or 467 arrays of items, both of which can be Parameterized (Section 3.1.2). 468 There can be zero or more members, and their names are unique in the 469 scope of the Dictionary they occur within. 471 Implementations MUST provide access to Dictionaries both by index and 472 by name. Specifications MAY use either means of accessing the 473 members. 475 The ABNF for Dictionaries is: 477 sh-dictionary = dict-member *( *SP "," *SP dict-member ) 478 dict-member = member-name [ "=" member-value ] 479 member-name = key 480 member-value = sh-item / inner-list 482 Members are separated by a comma with optional whitespace, while 483 names and values are separated by "=" (without whitespace). For 484 example: 486 Example-DictHeader: en="Applepie", da=:w4ZibGV0w6ZydGU=: 488 Members whose value is Boolean true MUST omit that value when 489 serialized. For example, here both "b" and "c" are true: 491 Example-DictHeader: a=?0, b, c; foo=bar 493 Note that this requirement is only on serialization; parsers are 494 still required to correctly handle the true Boolean value when it 495 appears in Dictionary values. 497 A Dictionary with a member whose value is an Inner List of tokens: 499 Example-DictListHeader: rating=1.5, feelings=(joy sadness) 501 A Dictionary with a mix of singular and list values, some with 502 Parameters: 504 Example-MixDict: a=(1 2), b=3, c=4;aa=bb, d=(5 6);valid 505 As with lists, an empty Dictionary is represented by omitting the 506 entire field. 508 Typically, a field specification will define the semantics of 509 Dictionaries by specifying the allowed type(s) for individual member 510 names, as well as whether their presence is required or optional. 511 Recipients MUST ignore names that are undefined or unknown, unless 512 the field's specification specifically disallows them. 514 Note that dictionaries can have their members split across multiple 515 lines inside a header or trailer section; for example, the following 516 are equivalent: 518 Example-Hdr: foo=1, bar=2 520 and 522 Example-Hdr: foo=1 523 Example-Hdr: bar=2 525 However, individual members of a Dictionary cannot be safely split 526 between lines; see Section 4.2 for details. 528 Parsers MUST support Dictionaries containing at least 1024 name/value 529 pairs, and names with at least 64 characters. 531 3.3. Items 533 An Item can be a Integer (Section 3.3.1), Decimal (Section 3.3.2), 534 String (Section 3.3.3), Token (Section 3.3.4), Byte Sequence 535 (Section 3.3.5), or Boolean (Section 3.3.6). It can have associated 536 Parameters (Section 3.1.2). 538 The ABNF for Items is: 540 sh-item = bare-item parameters 541 bare-item = sh-integer / sh-decimal / sh-string / sh-token 542 / sh-binary / sh-boolean 544 For example, a header field that is defined to be an Item that is an 545 Integer might look like: 547 Example-IntItemHeader: 5 549 or with Parameters: 551 Example-IntItemHeader: 5; foo=bar 553 3.3.1. Integers 555 Integers have a range of -999,999,999,999,999 to 999,999,999,999,999 556 inclusive (i.e., up to fifteen digits, signed), for IEEE 754 557 compatibility ([IEEE754]). 559 The ABNF for Integers is: 561 sh-integer = ["-"] 1*15DIGIT 563 For example: 565 Example-IntegerHeader: 42 567 Note that commas in Integers are used in this section's prose only 568 for readability; they are not valid in the wire format. 570 3.3.2. Decimals 572 Decimals are numbers with an integer and a fractional component. The 573 integer component has at most 12 digits; the fractional component has 574 at most three digits. 576 The ABNF for decimals is: 578 sh-decimal = ["-"] 1*12DIGIT "." 1*3DIGIT 580 For example, a header whose value is defined as a Decimal could look 581 like: 583 Example-DecimalHeader: 4.5 585 Note that the serialisation algorithm (Section 4.1.5) rounds input 586 with more than three digits of precision in the fractional component. 587 If an alternative rounding strategy is desired, this should be 588 specified by the header definition to occur before serialisation. 590 3.3.3. Strings 592 Strings are zero or more printable ASCII [RFC0020] characters (i.e., 593 the range %x20 to %x7E). Note that this excludes tabs, newlines, 594 carriage returns, etc. 596 The ABNF for Strings is: 598 sh-string = DQUOTE *(chr) DQUOTE 599 chr = unescaped / escaped 600 unescaped = %x20-21 / %x23-5B / %x5D-7E 601 escaped = "\" ( DQUOTE / "\" ) 603 Strings are delimited with double quotes, using a backslash ("\") to 604 escape double quotes and backslashes. For example: 606 Example-StringHeader: "hello world" 608 Note that Strings only use DQUOTE as a delimiter; single quotes do 609 not delimit Strings. Furthermore, only DQUOTE and "\" can be 610 escaped; other characters after "\" MUST cause parsing to fail. 612 Unicode is not directly supported in Strings, because it causes a 613 number of interoperability issues, and - with few exceptions - field 614 values do not require it. 616 When it is necessary for a field value to convey non-ASCII content, a 617 Byte Sequence (Section 3.3.5) can be specified, along with a 618 character encoding (preferably [UTF-8]). 620 Parsers MUST support Strings (after any decoding) with at least 1024 621 characters. 623 3.3.4. Tokens 625 Tokens are short textual words; their abstract model is identical to 626 their expression in the HTTP field value serialization. 628 The ABNF for Tokens is: 630 sh-token = ( ALPHA / "*" ) *( tchar / ":" / "/" ) 632 Parsers MUST support Tokens with at least 512 characters. 634 Note that Token allows the characters as the "token" ABNF rule 635 defined in [RFC7230], with the exceptions that the first character is 636 required to be either ALPHA or "*", and ":" and "/" are also allowed 637 in subsequent characters. 639 3.3.5. Byte Sequences 641 Byte Sequences can be conveyed in Structured Fields. 643 The ABNF for a Byte Sequence is: 645 sh-binary = ":" *(base64) ":" 646 base64 = ALPHA / DIGIT / "+" / "/" / "=" 648 A Byte Sequence is delimited with colons and encoded using base64 649 ([RFC4648], Section 4). For example: 651 Example-BinaryHdr: :cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==: 653 Parsers MUST support Byte Sequences with at least 16384 octets after 654 decoding. 656 3.3.6. Booleans 658 Boolean values can be conveyed in Structured Fields. 660 The ABNF for a Boolean is: 662 sh-boolean = "?" boolean 663 boolean = "0" / "1" 665 A Boolean is indicated with a leading "?" character followed by a "1" 666 for a true value or "0" for false. For example: 668 Example-BoolHdr: ?1 670 4. Working With Structured Fields in HTTP 672 This section defines how to serialize and parse Structured Fields in 673 field values, and protocols compatible with them (e.g., in HTTP/2 674 [RFC7540] before HPACK [RFC7541] is applied). 676 4.1. Serializing Structured Fields 678 Given a structure defined in this specification, return an ASCII 679 string suitable for use in a HTTP field value. 681 1. If the structure is a Dictionary or List and its value is empty 682 (i.e., it has no members), do not serialize the field at all 683 (i.e., omit both the field-name and field-value). 685 2. If the structure is a List, let output_string be the result of 686 running Serializing a List (Section 4.1.1) with the structure. 688 3. Else if the structure is a Dictionary, let output_string be the 689 result of running Serializing a Dictionary (Section 4.1.2) with 690 the structure. 692 4. Else if the structure is an Item, let output_string be the result 693 of running Serializing an Item (Section 4.1.3) with the 694 structure. 696 5. Else, fail serialization. 698 6. Return output_string converted into an array of bytes, using 699 ASCII encoding [RFC0020]. 701 4.1.1. Serializing a List 703 Given an array of (member_value, parameters) tuples as input_list, 704 return an ASCII string suitable for use in a HTTP field value. 706 1. Let output be an empty string. 708 2. For each (member_value, parameters) of input_list: 710 1. If member_value is an array, append the result of running 711 Serializing an Inner List (Section 4.1.1.1) with 712 (member_value, parameters) to output. 714 2. Otherwise, append the result of running Serializing an Item 715 (Section 4.1.3) with (member_value, parameters) to output. 717 3. If more member_values remain in input_list: 719 1. Append "," to output. 721 2. Append a single SP to output. 723 3. Return output. 725 4.1.1.1. Serializing an Inner List 727 Given an array of (member_value, parameters) tuples as inner_list, 728 and parameters as list_parameters, return an ASCII string suitable 729 for use in a HTTP field value. 731 1. Let output be the string "(". 733 2. For each (member_value, parameters) of inner_list: 735 1. Append the result of running Serializing an Item 736 (Section 4.1.3) with (member_value, parameters) to output. 738 2. If more values remain in inner_list, append a single SP to 739 output. 741 3. Append ")" to output. 743 4. Append the result of running Serializing Parameters 744 (Section 4.1.1.2) with list_parameters to output. 746 5. Return output. 748 4.1.1.2. Serializing Parameters 750 Given an ordered Dictionary as input_parameters (each member having a 751 param_name and a param_value), return an ASCII string suitable for 752 use in a HTTP field value. 754 1. Let output be an empty string. 756 2. For each param_name with a value of param_value in 757 input_parameters: 759 1. Append ";" to output. 761 2. Append the result of running Serializing a Key 762 (Section 4.1.1.3) with param_name to output. 764 3. If param_value is not Boolean true: 766 1. Append "=" to output. 768 2. Append the result of running Serializing a bare Item 769 (Section 4.1.3.1) with param_value to output. 771 3. Return output. 773 4.1.1.3. Serializing a Key 775 Given a key as input_key, return an ASCII string suitable for use in 776 a HTTP field value. 778 1. Convert input_key into a sequence of ASCII characters; if 779 conversion fails, fail serialization. 781 2. If input_key contains characters not in lcalpha, DIGIT, "_", "-", 782 ".", or "*" fail serialization. 784 3. If the first character of input_key is not lcalpha or "*", fail 785 serialization. 787 4. Let output be an empty string. 789 5. Append input_key to output. 791 6. Return output. 793 4.1.2. Serializing a Dictionary 795 Given an ordered Dictionary as input_dictionary (each member having a 796 member_name and a tuple value of (member_value, parameters)), return 797 an ASCII string suitable for use in a HTTP field value. 799 1. Let output be an empty string. 801 2. For each member_name with a value of (member_value, parameters) 802 in input_dictionary: 804 1. Append the result of running Serializing a Key 805 (Section 4.1.1.3) with member's member_name to output. 807 3. If member_value is Boolean true: 809 1. Append the result of running Serializing Parameters 810 (Section 4.1.1.2) with parameters to output. 812 4. Otherwise: 814 1. Append "=" to output. 816 2. If member_value is an array, append the result of running 817 Serializing an Inner List (Section 4.1.1.1) with 818 (member_value, parameters) to output. 820 3. Otherwise, append the result of running Serializing an Item 821 (Section 4.1.3) with (member_value, parameters) to output. 823 5. If more members remain in input_dictionary: 825 1. Append "," to output. 827 2. Append a single SP to output. 829 6. Return output. 831 4.1.3. Serializing an Item 833 Given an Item as bare_item and Parameters as item_parameters, return 834 an ASCII string suitable for use in a HTTP field value. 836 1. Let output be an empty string. 838 2. Append the result of running Serializing a Bare Item 839 Section 4.1.3.1 with bare_item to output. 841 3. Append the result of running Serializing Parameters 842 Section 4.1.1.2 with item_parameters to output. 844 4. Return output. 846 4.1.3.1. Serializing a Bare Item 848 Given an Item as input_item, return an ASCII string suitable for use 849 in a HTTP field value. 851 1. If input_item is an Integer, return the result of running 852 Serializing an Integer (Section 4.1.4) with input_item. 854 2. If input_item is a Decimal, return the result of running 855 Serializing a Decimal (Section 4.1.5) with input_item. 857 3. If input_item is a String, return the result of running 858 Serializing a String (Section 4.1.6) with input_item. 860 4. If input_item is a Token, return the result of running 861 Serializing a Token (Section 4.1.7) with input_item. 863 5. If input_item is a Boolean, return the result of running 864 Serializing a Boolean (Section 4.1.9) with input_item. 866 6. If input_item is a Byte Sequence, return the result of running 867 Serializing a Byte Sequence (Section 4.1.8) with input_item. 869 7. Otherwise, fail serialization. 871 4.1.4. Serializing an Integer 873 Given an Integer as input_integer, return an ASCII string suitable 874 for use in a HTTP field value. 876 1. If input_integer is not an integer in the range of 877 -999,999,999,999,999 to 999,999,999,999,999 inclusive, fail 878 serialization. 880 2. Let output be an empty string. 882 3. If input_integer is less than (but not equal to) 0, append "-" to 883 output. 885 4. Append input_integer's numeric value represented in base 10 using 886 only decimal digits to output. 888 5. Return output. 890 4.1.5. Serializing a Decimal 892 Given a decimal number as input_decimal, return an ASCII string 893 suitable for use in a HTTP field value. 895 1. If input_decimal is not a decimal number, fail serialization. 897 2. If input_decimal has more than three significant digits to the 898 right of the decimal point, round it to three decimal places, 899 rounding the final digit to the nearest value, or to the even 900 value if it is equidistant. 902 3. If input_decimal has more than 12 significant digits to the left 903 of the decimal point after rounding, fail serialization. 905 4. Let output be an empty string. 907 5. If input_decimal is less than (but not equal to) 0, append "-" 908 to output. 910 6. Append input_decimal's integer component represented in base 10 911 (using only decimal digits) to output; if it is zero, append 912 "0". 914 7. Append "." to output. 916 8. If input_decimal's fractional component is zero, append "0" to 917 output. 919 9. Otherwise, append the significant digits of input_decimal's 920 fractional component represented in base 10 (using only decimal 921 digits) to output. 923 10. Return output. 925 4.1.6. Serializing a String 927 Given a String as input_string, return an ASCII string suitable for 928 use in a HTTP field value. 930 1. Convert input_string into a sequence of ASCII characters; if 931 conversion fails, fail serialization. 933 2. If input_string contains characters in the range %x00-1f or %x7f 934 (i.e., not in VCHAR or SP), fail serialization. 936 3. Let output be an empty string. 938 4. Append DQUOTE to output. 940 5. For each character char in input_string: 942 1. If char is "\" or DQUOTE: 944 1. Append "\" to output. 946 2. Append char to output. 948 6. Append DQUOTE to output. 950 7. Return output. 952 4.1.7. Serializing a Token 954 Given a Token as input_token, return an ASCII string suitable for use 955 in a HTTP field value. 957 1. Convert input_token into a sequence of ASCII characters; if 958 conversion fails, fail serialization. 960 2. If the first character of input_token is not ALPHA or "*", or the 961 remaining portion contains a character not in tchar, ":" or "/", 962 fail serialization. 964 3. Let output be an empty string. 966 4. Append input_token to output. 968 5. Return output. 970 4.1.8. Serializing a Byte Sequence 972 Given a Byte Sequence as input_bytes, return an ASCII string suitable 973 for use in a HTTP field value. 975 1. If input_bytes is not a sequence of bytes, fail serialization. 977 2. Let output be an empty string. 979 3. Append ":" to output. 981 4. Append the result of base64-encoding input_bytes as per 982 [RFC4648], Section 4, taking account of the requirements below. 984 5. Append ":" to output. 986 6. Return output. 988 The encoded data is required to be padded with "=", as per [RFC4648], 989 Section 3.2. 991 Likewise, encoded data SHOULD have pad bits set to zero, as per 992 [RFC4648], Section 3.5, unless it is not possible to do so due to 993 implementation constraints. 995 4.1.9. Serializing a Boolean 997 Given a Boolean as input_boolean, return an ASCII string suitable for 998 use in a HTTP field value. 1000 1. If input_boolean is not a boolean, fail serialization. 1002 2. Let output be an empty string. 1004 3. Append "?" to output. 1006 4. If input_boolean is true, append "1" to output. 1008 5. If input_boolean is false, append "0" to output. 1010 6. Return output. 1012 4.2. Parsing Structured Fields 1014 When a receiving implementation parses HTTP fields that are known to 1015 be Structured Fields, it is important that care be taken, as there 1016 are a number of edge cases that can cause interoperability or even 1017 security problems. This section specifies the algorithm for doing 1018 so. 1020 Given an array of bytes input_bytes that represents the chosen 1021 field's field-value (which is empty if that field is not present), 1022 and field_type (one of "dictionary", "list", or "item"), return the 1023 parsed header value. 1025 1. Convert input_bytes into an ASCII string input_string; if 1026 conversion fails, fail parsing. 1028 2. Discard any leading SP characters from input_string. 1030 3. If field_type is "list", let output be the result of running 1031 Parsing a List (Section 4.2.1) with input_string. 1033 4. If field_type is "dictionary", let output be the result of 1034 running Parsing a Dictionary (Section 4.2.2) with input_string. 1036 5. If field_type is "item", let output be the result of running 1037 Parsing an Item (Section 4.2.3) with input_string. 1039 6. Discard any leading SP characters from input_string. 1041 7. If input_string is not empty, fail parsing. 1043 8. Otherwise, return output. 1045 When generating input_bytes, parsers MUST combine all lines in the 1046 same section (header or trailer) that case-insensitively match the 1047 field name into one comma-separated field-value, as per [RFC7230], 1048 Section 3.2.2; this assures that the entire field value is processed 1049 correctly. 1051 For Lists and Dictionaries, this has the effect of correctly 1052 concatenating all of the field's lines, as long as individual members 1053 of the top-level data structure are not split across multiple header 1054 instances. 1056 Strings split across multiple field lines will have unpredictable 1057 results, because comma(s) and whitespace inserted upon combination 1058 will become part of the string output by the parser. Since 1059 concatenation might be done by an upstream intermediary, the results 1060 are not under the control of the serializer or the parser. 1062 Tokens, Integers, Decimals and Byte Sequences cannot be split across 1063 multiple field lines because the inserted commas will cause parsing 1064 to fail. 1066 If parsing fails - including when calling another algorithm - the 1067 entire field value MUST be ignored (i.e., treated as if the field 1068 were not present in the section). This is intentionally strict, to 1069 improve interoperability and safety, and specifications referencing 1070 this document are not allowed to loosen this requirement. 1072 Note that this requirement does not apply to an implementation that 1073 is not parsing the field; for example, an intermediary is not 1074 required to strip a failing header field from a message before 1075 forwarding it. 1077 4.2.1. Parsing a List 1079 Given an ASCII string as input_string, return an array of 1080 (item_or_inner_list, parameters) tuples. input_string is modified to 1081 remove the parsed value. 1083 1. Let members be an empty array. 1085 2. While input_string is not empty: 1087 1. Append the result of running Parsing an Item or Inner List 1088 (Section 4.2.1.1) with input_string to members. 1090 2. Discard any leading SP characters from input_string. 1092 3. If input_string is empty, return members. 1094 4. Consume the first character of input_string; if it is not 1095 ",", fail parsing. 1097 5. Discard any leading SP characters from input_string. 1099 6. If input_string is empty, there is a trailing comma; fail 1100 parsing. 1102 3. No structured data has been found; return members (which is 1103 empty). 1105 4.2.1.1. Parsing an Item or Inner List 1107 Given an ASCII string as input_string, return the tuple 1108 (item_or_inner_list, parameters), where item_or_inner_list can be 1109 either a single bare item, or an array of (bare_item, parameters) 1110 tuples. input_string is modified to remove the parsed value. 1112 1. If the first character of input_string is "(", return the result 1113 of running Parsing an Inner List (Section 4.2.1.2) with 1114 input_string. 1116 2. Return the result of running Parsing an Item (Section 4.2.3) with 1117 input_string. 1119 4.2.1.2. Parsing an Inner List 1121 Given an ASCII string as input_string, return the tuple (inner_list, 1122 parameters), where inner_list is an array of (bare_item, parameters) 1123 tuples. input_string is modified to remove the parsed value. 1125 1. Consume the first character of input_string; if it is not "(", 1126 fail parsing. 1128 2. Let inner_list be an empty array. 1130 3. While input_string is not empty: 1132 1. Discard any leading SP characters from input_string. 1134 2. If the first character of input_string is ")": 1136 1. Consume the first character of input_string. 1138 2. Let parameters be the result of running Parsing 1139 Parameters (Section 4.2.3.2) with input_string. 1141 3. Return the tuple (inner_list, parameters). 1143 3. Let item be the result of running Parsing an Item 1144 (Section 4.2.3) with input_string. 1146 4. Append item to inner_list. 1148 5. If the first character of input_string is not SP or ")", fail 1149 parsing. 1151 4. The end of the inner list was not found; fail parsing. 1153 4.2.2. Parsing a Dictionary 1155 Given an ASCII string as input_string, return an ordered map whose 1156 values are (item_or_inner_list, parameters) tuples. input_string is 1157 modified to remove the parsed value. 1159 1. Let dictionary be an empty, ordered map. 1161 2. While input_string is not empty: 1163 1. Let this_key be the result of running Parsing a Key 1164 (Section 4.2.3.3) with input_string. 1166 2. If the first character of input_string is "=": 1168 1. Consume the first character of input_string. 1170 2. Let member be the result of running Parsing an Item or 1171 Inner List (Section 4.2.1.1) with input_string. 1173 3. Otherwise: 1175 1. Let value be Boolean true. 1177 2. Let parameters be the result of running Parsing 1178 Parameters Section 4.2.3.2 with input_string. 1180 3. Let member be the tuple (value, parameters). 1182 4. Add name this_key with value member to dictionary. If 1183 dictionary already contains a name this_key (comparing 1184 character-for-character), overwrite its value. 1186 5. Discard any leading SP characters from input_string. 1188 6. If input_string is empty, return dictionary. 1190 7. Consume the first character of input_string; if it is not 1191 ",", fail parsing. 1193 8. Discard any leading SP characters from input_string. 1195 9. If input_string is empty, there is a trailing comma; fail 1196 parsing. 1198 3. No structured data has been found; return dictionary (which is 1199 empty). 1201 4.2.3. Parsing an Item 1203 Given an ASCII string as input_string, return a (bare_item, 1204 parameters) tuple. input_string is modified to remove the parsed 1205 value. 1207 1. Let bare_item be the result of running Parsing a Bare Item 1208 (Section 4.2.3.1) with input_string. 1210 2. Let parameters be the result of running Parsing Parameters 1211 (Section 4.2.3.2) with input_string. 1213 3. Return the tuple (bare_item, parameters). 1215 4.2.3.1. Parsing a Bare Item 1217 Given an ASCII string as input_string, return a bare Item. 1218 input_string is modified to remove the parsed value. 1220 1. If the first character of input_string is a "-" or a DIGIT, 1221 return the result of running Parsing an Integer or Decimal 1222 (Section 4.2.4) with input_string. 1224 2. If the first character of input_string is a DQUOTE, return the 1225 result of running Parsing a String (Section 4.2.5) with 1226 input_string. 1228 3. If the first character of input_string is ":", return the result 1229 of running Parsing a Byte Sequence (Section 4.2.7) with 1230 input_string. 1232 4. If the first character of input_string is "?", return the result 1233 of running Parsing a Boolean (Section 4.2.8) with input_string. 1235 5. If the first character of input_string is an ALPHA or "*", return 1236 the result of running Parsing a Token (Section 4.2.6) with 1237 input_string. 1239 6. Otherwise, the item type is unrecognized; fail parsing. 1241 4.2.3.2. Parsing Parameters 1243 Given an ASCII string as input_string, return an ordered map whose 1244 values are bare Items. input_string is modified to remove the parsed 1245 value. 1247 1. Let parameters be an empty, ordered map. 1249 2. While input_string is not empty: 1251 1. If the first character of input_string is not ";", exit the 1252 loop. 1254 2. Consume a ";" character from the beginning of input_string. 1256 3. Discard any leading SP characters from input_string. 1258 4. let param_name be the result of running Parsing a Key 1259 (Section 4.2.3.3) with input_string. 1261 5. Let param_value be Boolean true. 1263 6. If the first character of input_string is "=": 1265 1. Consume the "=" character at the beginning of 1266 input_string. 1268 2. Let param_value be the result of running Parsing a Bare 1269 Item (Section 4.2.3.1) with input_string. 1271 7. Append key param_name with value param_value to parameters. 1272 If parameters already contains a name param_name (comparing 1273 character-for-character), overwrite its value. 1275 3. Return parameters. 1277 4.2.3.3. Parsing a Key 1279 Given an ASCII string as input_string, return a key. input_string is 1280 modified to remove the parsed value. 1282 1. If the first character of input_string is not lcalpha or "*", 1283 fail parsing. 1285 2. Let output_string be an empty string. 1287 3. While input_string is not empty: 1289 1. If the first character of input_string is not one of lcalpha, 1290 DIGIT, "_", "-", ".", or "*", return output_string. 1292 2. Let char be the result of consuming the first character of 1293 input_string. 1295 3. Append char to output_string. 1297 4. Return output_string. 1299 4.2.4. Parsing an Integer or Decimal 1301 Given an ASCII string as input_string, return an Integer or Decimal. 1302 input_string is modified to remove the parsed value. 1304 NOTE: This algorithm parses both Integers (Section 3.3.1) and 1305 Decimals (Section 3.3.2), and returns the corresponding structure. 1307 1. Let type be "integer". 1309 2. Let sign be 1. 1311 3. Let input_number be an empty string. 1313 4. If the first character of input_string is "-", consume it and 1314 set sign to -1. 1316 5. If input_string is empty, there is an empty integer; fail 1317 parsing. 1319 6. If the first character of input_string is not a DIGIT, fail 1320 parsing. 1322 7. While input_string is not empty: 1324 1. Let char be the result of consuming the first character of 1325 input_string. 1327 2. If char is a DIGIT, append it to input_number. 1329 3. Else, if type is "integer" and char is ".": 1331 1. If input_number contains more than 12 characters, fail 1332 parsing. 1334 2. Otherwise, append char to input_number and set type to 1335 "decimal". 1337 4. Otherwise, prepend char to input_string, and exit the loop. 1339 5. If type is "integer" and input_number contains more than 15 1340 characters, fail parsing. 1342 6. If type is "decimal" and input_number contains more than 16 1343 characters, fail parsing. 1345 8. If type is "integer": 1347 1. Parse input_number as an integer and let output_number be 1348 the product of the result and sign. 1350 2. If output_number is outside the range -999,999,999,999,999 1351 to 999,999,999,999,999 inclusive, fail parsing. 1353 9. Otherwise: 1355 1. If the final character of input_number is ".", fail parsing. 1357 2. If the number of characters after "." in input_number is 1358 greater than three, fail parsing. 1360 3. Parse input_number as a decimal number and let output_number 1361 be the product of the result and sign. 1363 10. Return output_number. 1365 4.2.5. Parsing a String 1367 Given an ASCII string as input_string, return an unquoted String. 1368 input_string is modified to remove the parsed value. 1370 1. Let output_string be an empty string. 1372 2. If the first character of input_string is not DQUOTE, fail 1373 parsing. 1375 3. Discard the first character of input_string. 1377 4. While input_string is not empty: 1379 1. Let char be the result of consuming the first character of 1380 input_string. 1382 2. If char is a backslash ("\"): 1384 1. If input_string is now empty, fail parsing. 1386 2. Let next_char be the result of consuming the first 1387 character of input_string. 1389 3. If next_char is not DQUOTE or "\", fail parsing. 1391 4. Append next_char to output_string. 1393 3. Else, if char is DQUOTE, return output_string. 1395 4. Else, if char is in the range %x00-1f or %x7f (i.e., is not 1396 in VCHAR or SP), fail parsing. 1398 5. Else, append char to output_string. 1400 5. Reached the end of input_string without finding a closing DQUOTE; 1401 fail parsing. 1403 4.2.6. Parsing a Token 1405 Given an ASCII string as input_string, return a Token. input_string 1406 is modified to remove the parsed value. 1408 1. If the first character of input_string is not ALPHA or "*", fail 1409 parsing. 1411 2. Let output_string be an empty string. 1413 3. While input_string is not empty: 1415 1. If the first character of input_string is not in tchar, ":" 1416 or "/", return output_string. 1418 2. Let char be the result of consuming the first character of 1419 input_string. 1421 3. Append char to output_string. 1423 4. Return output_string. 1425 4.2.7. Parsing a Byte Sequence 1427 Given an ASCII string as input_string, return a Byte Sequence. 1428 input_string is modified to remove the parsed value. 1430 1. If the first character of input_string is not ":", fail parsing. 1432 2. Discard the first character of input_string. 1434 3. If there is not a ":" character before the end of input_string, 1435 fail parsing. 1437 4. Let b64_content be the result of consuming content of 1438 input_string up to but not including the first instance of the 1439 character ":". 1441 5. Consume the ":" character at the beginning of input_string. 1443 6. If b64_content contains a character not included in ALPHA, DIGIT, 1444 "+", "/" and "=", fail parsing. 1446 7. Let binary_content be the result of Base 64 Decoding [RFC4648] 1447 b64_content, synthesizing padding if necessary (note the 1448 requirements about recipient behavior below). 1450 8. Return binary_content. 1452 Because some implementations of base64 do not allow reject of encoded 1453 data that is not properly "=" padded (see [RFC4648], Section 3.2), 1454 parsers SHOULD NOT fail when it is not present, unless they cannot be 1455 configured to do so. 1457 Because some implementations of base64 do not allow rejection of 1458 encoded data that has non-zero pad bits (see [RFC4648], Section 3.5), 1459 parsers SHOULD NOT fail when it is present, unless they cannot be 1460 configured to do so. 1462 This specification does not relax the requirements in [RFC4648], 1463 Section 3.1 and 3.3; therefore, parsers MUST fail on characters 1464 outside the base64 alphabet, and on line feeds in encoded data. 1466 4.2.8. Parsing a Boolean 1468 Given an ASCII string as input_string, return a Boolean. input_string 1469 is modified to remove the parsed value. 1471 1. If the first character of input_string is not "?", fail parsing. 1473 2. Discard the first character of input_string. 1475 3. If the first character of input_string matches "1", discard the 1476 first character, and return true. 1478 4. If the first character of input_string matches "0", discard the 1479 first character, and return false. 1481 5. No value has matched; fail parsing. 1483 5. IANA Considerations 1485 This document has no actions for IANA. 1487 6. Security Considerations 1489 The size of most types defined by Structured Fields is not limited; 1490 as a result, extremely large fields could be an attack vector (e.g., 1491 for resource consumption). Most HTTP implementations limit the sizes 1492 of individual fields as well as the overall header or trailer section 1493 size to mitigate such attacks. 1495 It is possible for parties with the ability to inject new HTTP fields 1496 to change the meaning of a Structured Field. In some circumstances, 1497 this will cause parsing to fail, but it is not possible to reliably 1498 fail in all such circumstances. 1500 7. References 1502 7.1. Normative References 1504 [RFC0020] Cerf, V., "ASCII format for network interchange", STD 80, 1505 RFC 20, DOI 10.17487/RFC0020, October 1969, 1506 . 1508 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1509 Requirement Levels", BCP 14, RFC 2119, 1510 DOI 10.17487/RFC2119, March 1997, 1511 . 1513 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 1514 Encodings", RFC 4648, DOI 10.17487/RFC4648, October 2006, 1515 . 1517 [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax 1518 Specifications: ABNF", STD 68, RFC 5234, 1519 DOI 10.17487/RFC5234, January 2008, 1520 . 1522 [RFC7230] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 1523 Protocol (HTTP/1.1): Message Syntax and Routing", 1524 RFC 7230, DOI 10.17487/RFC7230, June 2014, 1525 . 1527 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 1528 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 1529 May 2017, . 1531 7.2. Informative References 1533 [IEEE754] IEEE, "IEEE Standard for Floating-Point Arithmetic", 1534 IEEE 754-2019, DOI 10.1109/IEEESTD.2019.8766229, 1535 ISBN 978-1-5044-5924-2, July 2019, 1536 . 1538 [RFC7231] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 1539 Protocol (HTTP/1.1): Semantics and Content", RFC 7231, 1540 DOI 10.17487/RFC7231, June 2014, 1541 . 1543 [RFC7493] Bray, T., Ed., "The I-JSON Message Format", RFC 7493, 1544 DOI 10.17487/RFC7493, March 2015, 1545 . 1547 [RFC7540] Belshe, M., Peon, R., and M. Thomson, Ed., "Hypertext 1548 Transfer Protocol Version 2 (HTTP/2)", RFC 7540, 1549 DOI 10.17487/RFC7540, May 2015, 1550 . 1552 [RFC7541] Peon, R. and H. Ruellan, "HPACK: Header Compression for 1553 HTTP/2", RFC 7541, DOI 10.17487/RFC7541, May 2015, 1554 . 1556 [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 1557 Interchange Format", STD 90, RFC 8259, 1558 DOI 10.17487/RFC8259, December 2017, 1559 . 1561 [UTF-8] Yergeau, F., "UTF-8, a transformation format of ISO 1562 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, November 1563 2003, . 1565 7.3. URIs 1567 [1] https://lists.w3.org/Archives/Public/ietf-http-wg/ 1569 [2] https://httpwg.github.io/ 1571 [3] https://github.com/httpwg/http-extensions/labels/header-structure 1573 [4] https://github.com/httpwg/structured-header-tests 1575 [5] https://github.com/httpwg/wiki/wiki/Structured-Headers 1577 [6] https://github.com/httpwg/structured-header-tests 1579 Appendix A. Frequently Asked Questions 1581 A.1. Why not JSON? 1583 Earlier proposals for Structured Fields were based upon JSON 1584 [RFC8259]. However, constraining its use to make it suitable for 1585 HTTP header fields required senders and recipients to implement 1586 specific additional handling. 1588 For example, JSON has specification issues around large numbers and 1589 objects with duplicate members. Although advice for avoiding these 1590 issues is available (e.g., [RFC7493]), it cannot be relied upon. 1592 Likewise, JSON strings are by default Unicode strings, which have a 1593 number of potential interoperability issues (e.g., in comparison). 1594 Although implementers can be advised to avoid non-ASCII content where 1595 unnecessary, this is difficult to enforce. 1597 Another example is JSON's ability to nest content to arbitrary 1598 depths. Since the resulting memory commitment might be unsuitable 1599 (e.g., in embedded and other limited server deployments), it's 1600 necessary to limit it in some fashion; however, existing JSON 1601 implementations have no such limits, and even if a limit is 1602 specified, it's likely that some field definition will find a need to 1603 violate it. 1605 Because of JSON's broad adoption and implementation, it is difficult 1606 to impose such additional constraints across all implementations; 1607 some deployments would fail to enforce them, thereby harming 1608 interoperability. In short, if it looks like JSON, people will be 1609 tempted to use a JSON parser / serializer on field values. 1611 Since a major goal for Structured Fields is to improve 1612 interoperability and simplify implementation, these concerns led to a 1613 format that requires a dedicated parser and serializer. 1615 Additionally, there were widely shared feelings that JSON doesn't 1616 "look right" in HTTP fields. 1618 Appendix B. Implementation Notes 1620 A generic implementation of this specification should expose the top- 1621 level serialize (Section 4.1) and parse (Section 4.2) functions. 1622 They need not be functions; for example, it could be implemented as 1623 an object, with methods for each of the different top-level types. 1625 For interoperability, it's important that generic implementations be 1626 complete and follow the algorithms closely; see Section 1.1. To aid 1627 this, a common test suite is being maintained by the community at 1628 https://github.com/httpwg/structured-header-tests [6]. 1630 Implementers should note that Dictionaries and Parameters are order- 1631 preserving maps. Some fields may not convey meaning in the ordering 1632 of these data types, but it should still be exposed so that 1633 applications which need to use it will have it available. 1635 Likewise, implementations should note that it's important to preserve 1636 the distinction between Tokens and Strings. While most programming 1637 languages have native types that map to the other types well, it may 1638 be necessary to create a wrapper "token" object or use a parameter on 1639 functions to assure that these types remain separate. 1641 The serialization algorithm is defined in a way that it is not 1642 strictly limited to the data types defined in Section 3 in every 1643 case. For example, Decimals are designed to take broader input and 1644 round to allowed values. 1646 Appendix C. Changes 1648 _RFC Editor: Please remove this section before publication._ 1650 C.1. Since draft-ietf-httpbis-header-structure-15 1652 o Editorial improvements. 1654 o Use HTTP field terminology more consistently, in line with recent 1655 changes to HTTP-core. 1657 o String length requirements apply to decoded strings (#1051). 1659 o Correctly round decimals in serialisation (#1043). 1661 o Clarify input to serialisation algorithms (#1055). 1663 o Omitted True dictionary value can have parameters (#1083). 1665 o Keys can now start with '*' (#1068). 1667 C.2. Since draft-ietf-httpbis-header-structure-14 1669 o Editorial improvements. 1671 o Allow empty dictionary values (#992). 1673 o Change value of omitted parameter value to True (#995). 1675 o Explain more about splitting dictionaries and lists across header 1676 instances (#997). 1678 o Disallow HTAB, replace OWS with spaces (#998). 1680 o Change byte sequence delimiters from "*" to ":" (#991). 1682 o Allow tokens to start with "*" (#991). 1684 o Change Floats to fixed-precision Decimals (#982). 1686 o Round the fractional component of decimal, rather than truncating 1687 it (#982). 1689 o Handle duplicate dictionary and parameter keys by overwriting 1690 their values, rather than failing (#997). 1692 o Allow "." in key (#1027). 1694 o Check first character of key in serialisation (#1037). 1696 o Talk about greasing headers (#1015). 1698 C.3. Since draft-ietf-httpbis-header-structure-13 1700 o Editorial improvements. 1702 o Define "structured header name" and "structured header value" 1703 terms (#908). 1705 o Corrected text about valid characters in strings (#931). 1707 o Removed most instances of the word "textual", as it was redundant 1708 (#915). 1710 o Allowed parameters on Items and Inner Lists (#907). 1712 o Expand the range of characters in token (#961). 1714 o Disallow OWS before ";" delimiter in parameters (#961). 1716 C.4. Since draft-ietf-httpbis-header-structure-12 1718 o Editorial improvements. 1720 o Reworked float serialisation (#896). 1722 o Don't add a trailing space in inner-list (#904). 1724 C.5. Since draft-ietf-httpbis-header-structure-11 1726 o Allow * in key (#844). 1728 o Constrain floats to six digits of precision (#848). 1730 o Allow dictionary members to have parameters (#842). 1732 C.6. Since draft-ietf-httpbis-header-structure-10 1734 o Update abstract (#799). 1736 o Input and output are now arrays of bytes (#662). 1738 o Implementations need to preserve difference between token and 1739 string (#790). 1741 o Allow empty dictionaries and lists (#781). 1743 o Change parameterized lists to have primary items (#797). 1745 o Allow inner lists in both dictionaries and lists; removes lists of 1746 lists (#816). 1748 o Subsume Parameterised Lists into Lists (#839). 1750 C.7. Since draft-ietf-httpbis-header-structure-09 1752 o Changed Boolean from T/F to 1/0 (#784). 1754 o Parameters are now ordered maps (#765). 1756 o Clamp integers to 15 digits (#737). 1758 C.8. Since draft-ietf-httpbis-header-structure-08 1760 o Disallow whitespace before items properly (#703). 1762 o Created "key" for use in dictionaries and parameters, rather than 1763 relying on identifier (#702). Identifiers have a separate minimum 1764 supported size. 1766 o Expanded the range of special characters allowed in identifier to 1767 include all of ALPHA, ".", ":", and "%" (#702). 1769 o Use "?" instead of "!" to indicate a Boolean (#719). 1771 o Added "Intentionally Strict Processing" (#684). 1773 o Gave better names for referring specs to use in Parameterised 1774 Lists (#720). 1776 o Added Lists of Lists (#721). 1778 o Rename Identifier to Token (#725). 1780 o Add implementation guidance (#727). 1782 C.9. Since draft-ietf-httpbis-header-structure-07 1784 o Make Dictionaries ordered mappings (#659). 1786 o Changed "binary content" to "byte sequence" to align with Infra 1787 specification (#671). 1789 o Changed "mapping" to "map" for #671. 1791 o Don't fail if byte sequences aren't "=" padded (#658). 1793 o Add Booleans (#683). 1795 o Allow identifiers in items again (#629). 1797 o Disallowed whitespace before items (#703). 1799 o Explain the consequences of splitting a string across multiple 1800 headers (#686). 1802 C.10. Since draft-ietf-httpbis-header-structure-06 1804 o Add a FAQ. 1806 o Allow non-zero pad bits. 1808 o Explicitly check for integers that violate constraints. 1810 C.11. Since draft-ietf-httpbis-header-structure-05 1812 o Reorganise specification to separate parsing out. 1814 o Allow referencing specs to use ABNF. 1816 o Define serialisation algorithms. 1818 o Refine relationship between ABNF, parsing and serialisation 1819 algorithms. 1821 C.12. Since draft-ietf-httpbis-header-structure-04 1823 o Remove identifiers from item. 1825 o Remove most limits on sizes. 1827 o Refine number parsing. 1829 C.13. Since draft-ietf-httpbis-header-structure-03 1831 o Strengthen language around failure handling. 1833 C.14. Since draft-ietf-httpbis-header-structure-02 1835 o Split Numbers into Integers and Floats. 1837 o Define number parsing. 1839 o Tighten up binary parsing and give it an explicit end delimiter. 1841 o Clarify that mappings are unordered. 1843 o Allow zero-length strings. 1845 o Improve string parsing algorithm. 1847 o Improve limits in algorithms. 1849 o Require parsers to combine header fields before processing. 1851 o Throw an error on trailing garbage. 1853 C.15. Since draft-ietf-httpbis-header-structure-01 1855 o Replaced with draft-nottingham-structured-headers. 1857 C.16. Since draft-ietf-httpbis-header-structure-00 1859 o Added signed 64bit integer type. 1861 o Drop UTF8, and settle on BCP137 ::EmbeddedUnicodeChar for h1- 1862 unicode-string. 1864 o Change h1_blob delimiter to ":" since "'" is valid t_char 1866 Acknowledgements 1868 Many thanks to Matthew Kerwin for his detailed feedback and careful 1869 consideration during the development of this specification. 1871 Thanks also to Ian Clelland, Roy Fielding, Anne van Kesteren, Kazuho 1872 Oku, Evert Pot, Julian Reschke, Martin Thomson, Mike West, and 1873 Jeffrey Yasskin for their contributions. 1875 Authors' Addresses 1877 Mark Nottingham 1878 Fastly 1880 Email: mnot@mnot.net 1881 URI: https://www.mnot.net/ 1883 Poul-Henning Kamp 1884 The Varnish Cache Project 1886 Email: phk@varnish-cache.org