HTTP Working Group | M. Nottingham |
Internet-Draft | Fastly |
Intended status: Standards Track | P-H. Kamp |
Expires: August 5, 2018 | The Varnish Cache Project |
February 1, 2018 |
This document describes a set of data types and parsing algorithms associated with them that are intended to make it easier and safer to define and handle HTTP header fields. It is intended for use by new specifications of HTTP header fields as well as revisions of existing header field specifications when doing so does not cause interoperability issues.¶
RFC EDITOR: please remove this section before publication ¶
Discussion of this draft takes place on the HTTP working group mailing list (ietf-http-wg@w3.org), which is archived at https://lists.w3.org/Archives/Public/ietf-http-wg/.¶
Working Group information can be found at https://httpwg.github.io/; source code and issues list for this draft can be found at https://github.com/httpwg/http-extensions/labels/header-structure.¶
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.¶
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.¶
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as “work in progress”.¶
This Internet-Draft will expire on August 5, 2018.¶
Copyright (c) 2018 IETF Trust and the persons identified as the document authors. All rights reserved.¶
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.¶
Specifying the syntax of new HTTP header fields is an onerous task; even with the guidance in [RFC7231], Section 8.3.1, there are many decisions – and pitfalls – for a prospective HTTP header field author.¶
Once a header field is defined, bespoke parsers for it often need to be written, because each header has slightly different handling of what looks like common syntax.¶
This document introduces structured HTTP header field values (hereafter, Structured Headers) to address these problems. Structured Headers define a generic, abstract model for header field values, along with a concrete serialisation for expressing that model in textual HTTP headers, as used by HTTP/1 [RFC7230] and HTTP/2 [RFC7540].¶
HTTP headers that are defined as Structured Headers use the types defined in this specification to define their syntax and basic handling rules, thereby simplifying both their definition and parsing.¶
Additionally, future versions of HTTP can define alternative serialisations of the abstract model of Structured Headers, allowing headers that use it to be transmitted more efficiently without being redefined.¶
Note that it is not a goal of this document to redefine the syntax of existing HTTP headers; the mechanisms described herein are only intended to be used with headers that explicitly opt into them.¶
Section 4 defines a number of abstract data types that can be used in Structured Headers. Dictionaries and lists are only usable at the “top” level, while the remaining types can be specified appear at the top level or inside those structures.¶
Those abstract types can be serialised into textual headers – such as those used in HTTP/1 and HTTP/2 – using the algorithms described in Section 3.¶
A HTTP header that uses Structured Headers need to be defined to do so explicitly; recipients and generators need to know that the requirements of this document are in effect. The simplest way to do that is by referencing this document in its definition.¶
The field’s definition will also need to specify the field-value’s allowed syntax, in terms of the types described in Section 4, along with their associated semantics.¶
A header field definition cannot relax or otherwise modify the requirements of this specification; doing so would preclude handling by generic software.¶
However, header field authors are encouraged to clearly state additional constraints upon the syntax, as well as the consequences when those constraints are violated. Such additional constraints could include additional structure (e.g., a list of URLs [RFC3986] inside a string) that cannot be expressed using the primitives defined here.¶
For example:¶
# FooExample Header The FooExample HTTP header field conveys a list of integers about how much Foo the sender has. FooExample is a Structured header [RFCxxxx]. Its value MUST be a dictionary ([RFCxxxx], Section Y.Y). The dictionary MUST contain: * A member whose key is "foo", and whose value is an integer ([RFCxxxx], Section Y.Y), indicating the number of foos in the message. * A member whose key is "barUrls", and whose value is a string ([RFCxxxx], Section Y.Y), conveying the Bar URLs for the message. See below for processing requirements. If the parsed header field does not contain both, it MUST be ignored. "barUrls" contains a space-separated list of URI-references ([RFC3986], Section 4.1): barURLs = URI-reference *( 1*SP URI-reference ) If a member of barURLs is not a valid URI-reference, it MUST be ignored. If a member of barURLs is a relative reference ([RFC3986], Section 4.2), it MUST be resolved ([RFC3986], Section 5) before being used.
Note that empty header field values are not allowed by the syntax, and therefore will be considered errors.¶
When a receiving implementation parses textual HTTP header fields (e.g., in HTTP/1 or HTTP/2) that are known to be Structured Headers, it is important that care be taken, as there are a number of edge cases that can cause interoperability or even security problems. This section specifies the algorithm for doing so.¶
Given an ASCII string input_string that represents the chosen header’s field-value, return the parsed header value.¶
When generating input_string for a given header field, parsers MUST combine all instances of it into one comma-separated field-value, as per [RFC7230], Section 3.2.2; this assures that the header is processed correctly.¶
Note that in the case of lists and dictionaries, this has the effect of coalescing all of the values for that field. However, for singular items and parameterised labels, it will result in an error being thrown.¶
Additionally, note that the effect of the parsing algorithms as specified is generally intolerant of syntax errors; if one is encountered, the typical response is to throw an error, thereby discarding the entire header field value. This includes any non-ASCII characters in input_string.¶
This section defines the abstract value types that can be composed into Structured Headers, along with the textual HTTP serialisations of them.¶
Dictionaries are unordered maps of key-value pairs, where the keys are labels (Section 4.8) and the values are items (Section 4.4). There can be between 1 and 1024 members, and keys are required to be unique.¶
In the textual HTTP serialisation, keys and values are separated by “=” (without whitespace), and key/value pairs are separated by a comma with optional whitespace. Duplicate keys MUST be considered an error.¶
dictionary = label "=" item *1023( OWS "," OWS label "=" item )
For example, a header field whose value is defined as a dictionary could look like:¶
ExampleDictHeader: foo=1.23, en="Applepie", da=*w4ZibGV0w6ZydGUK
Typically, a header field specification will define the semantics of individual keys, as well as whether their presence is required or optional. Recipients MUST ignore keys that are undefined or unknown, unless the header field’s specification specifically disallows them.¶
Given an ASCII string input_string, return a mapping of (label, item). input_string is modified to remove the parsed value.¶
Lists are arrays of items (Section 4.4) or parameterised labels (Section 4.3), with one to 1024 members.¶
In the textual HTTP serialisation, each member is separated by a comma and optional whitespace.¶
list = list_member 0*1023( OWS "," OWS list_member ) list_member = item / parameterised
For example, a header field whose value is defined as a list of labels could look like:¶
ExampleLabelListHeader: foo, bar, baz_45
and a header field whose value is defined as a list of parameterised labels could look like:¶
ExampleParamListHeader: abc/def; g="hi";j, klm/nop
Given an ASCII string input_string, return a list of items. input_string is modified to remove the parsed value.¶
Parameterised Labels are labels (Section 4.8) with up to 256 parameters; each parameter has a label and an optional value that is an item (Section 4.4). Ordering between parameters is not significant, and duplicate parameters MUST be considered an error.¶
The textual HTTP serialisation uses semicolons (“;”) to delimit the parameters from each other, and equals (“=”) to delimit the parameter name from its value.¶
parameterised = label *256( OWS ";" OWS label [ "=" item ] )
For example,¶
ExampleParamHeader: abc_123;a=1;b=2; c
Given an ASCII string input_string, return a label with an mapping of parameters. input_string is modified to remove the parsed value.¶
An item is can be a integer (Section 4.5), float (Section 4.6), string (Section 4.7), label (Section 4.8) or binary content (Section 4.9).¶
item = integer / float / string / label / binary
Given an ASCII string input_string, return an item. input_string is modified to remove the parsed value.¶
Abstractly, integers have a range of −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 inclusive (i.e., a 64-bit signed integer).¶
integer = ["-"] 1*19DIGIT
Parsers that encounter an integer outside the range defined above MUST throw an error. Therefore, the value “9223372036854775809” would be invalid. Likewise, values that do not conform to the ABNF above are invalid, and MUST throw an error.¶
For example, a header whose value is defined as a integer could look like:¶
ExampleIntegerHeader: 42
NOTE: This algorithm parses both Integers and Floats Section 4.6, and returns the corresponding structure.¶
Abstractly, floats are integers with a fractional part. They have a maximum of fifteen digits available to be used in both of the parts, as reflected in the ABNF below; this allows them to be stored as IEEE 754 double precision numbers (binary64) ([IEEE754]).¶
The textual HTTP serialisation of floats allows a maximum of fifteen digits between the integer and fractional part, with at least one required on each side, along with an optional “-“ indicating negative numbers.¶
float = ["-"] ( DIGIT "." 1*14DIGIT / 2DIGIT "." 1*13DIGIT / 3DIGIT "." 1*12DIGIT / 4DIGIT "." 1*11DIGIT / 5DIGIT "." 1*10DIGIT / 6DIGIT "." 1*9DIGIT / 7DIGIT "." 1*8DIGIT / 8DIGIT "." 1*7DIGIT / 9DIGIT "." 1*6DIGIT / 10DIGIT "." 1*5DIGIT / 11DIGIT "." 1*4DIGIT / 12DIGIT "." 1*3DIGIT / 13DIGIT "." 1*2DIGIT / 14DIGIT "." 1DIGIT )
Values that do not conform to the ABNF above are invalid, and MUST throw an error.¶
For example, a header whose value is defined as a float could look like:¶
ExampleFloatHeader: 4.5
See Section 4.5.1 for the parsing algorithm for floats.¶
Abstractly, strings are ASCII strings [RFC0020], excluding control characters (i.e., the range 0x20 to 0x7E). Note that this excludes tabs, newlines and carriage returns. They may be at most 1024 characters long.¶
The textual HTTP serialisation of strings uses a backslash (“") to escape double quotes and backslashes in strings.¶
string = DQUOTE 0*1024(char) DQUOTE char = unescaped / escape ( DQUOTE / "\" ) unescaped = %x20-21 / %x23-5B / %x5D-7E escape = "\"
For example, a header whose value is defined as a string could look like:¶
ExampleStringHeader: "hello world"
Note that strings only use DQUOTE as a delimiter; single quotes do not delimit strings. Furthermore, only DQUOTE and “" can be escaped; other sequences MUST generate an error.¶
Unicode is not directly supported in Structured Headers, because it causes a number of interoperability issues, and – with few exceptions – header values do not require it.¶
When it is necessary for a field value to convey non-ASCII string content, binary content (Section 4.9) SHOULD be specified, along with a character encoding (most likely, UTF-8).¶
Given an ASCII string input_string, return an unquoted string. input_string is modified to remove the parsed value.¶
Labels are short (up to 256 characters) textual identifiers; their abstract model is identical to their expression in the textual HTTP serialisation.¶
label = lcalpha *255( lcalpha / DIGIT / "_" / "-"/ "*" / "/" ) lcalpha = %x61-7A ; a-z
Note that labels can only contain lowercase letters.¶
For example, a header whose value is defined as a label could look like:¶
ExampleLabelHeader: foo/bar
Given an ASCII string input_string, return a label. input_string is modified to remove the parsed value.¶
Arbitrary binary content up to 16K in size can be conveyed in Structured Headers.¶
The textual HTTP serialisation indicates their presence by a leading “*”, with the data encoded using Base 64 Encoding [RFC4648], Section 4.¶
Parsers MUST consider encoded data that is padded an error, as “=” might be confused with the use of dictionaries). See [RFC4648], Section 3.2.¶
Likewise, parsers MUST consider encoded data that has non-zero pad bits an error. See [RFC4648], Section 3.5.¶
This specification does not relax the requirements in [RFC4648], Section 3.1 and 3.3; therefore, parsers MUST consider characters outside the base64 alphabet and line feeds in encoded data as errors.¶
binary = "*" 0*21846(base64) "*" base64 = ALPHA / DIGIT / "+" / "/"
For example, a header whose value is defined as binary content could look like:¶
ExampleBinaryHeader: *cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg*
Given an ASCII string input_string, return binary content. input_string is modified to remove the parsed value.¶
This draft has no actions for IANA.¶
TBD¶