Skip to main content

Appendices

HTML [W3C.REC-html5-20141028]定义了<link>元素用于传达链接。例如:

`<link rel="stylesheet" href="/style.css" type="text/css">`

HTML链接与本规范中定义的链接模型之间的对应关系如下:

  • 链接上下文是包含链接元素的文档的URI
  • 链接关系类型由"rel"属性的值标识
  • 链接目标由"href"属性的值标识
  • 目标属性由其他属性(如"type"、"media"等)表示

Atom [RFC4287]定义了一个链接元素,可以出现在feed和entry中。例如:

<link rel="alternate" type="text/html" 
href="http://example.org/"/>

Atom链接与本规范中定义的链接模型之间的对应关系如下:

  • 链接上下文是包含链接元素的feed或entry的URI
  • 链接关系类型由"rel"属性的值标识
  • 链接目标由"href"属性的值标识
  • 目标属性由其他属性(如"type"、"hreflang"等)表示

Appendix B. Algorithms for Parsing Link Header Fields (解析Link头字段的算法)

本附录定义了解析Link头字段的算法。这些算法是规范性的。

给定一组HTTP头字段headers:

  1. 让links为空列表
  2. 对于headers中的每个字段field,其字段名为"Link"(不区分大小写):
    • 让field_value为field的字段值
    • 让field_links为解析field_value的结果(使用B.2节中的算法)
    • 将field_links中的每个链接添加到links
  3. 返回links

To parse a Link field value, process the field value from left to right and produce zero or more link-values:

  1. Split the field value on commas that are not inside a quoted string.
  2. For each resulting link-value, remove leading and trailing optional whitespace.
  3. The link target MUST be enclosed in angle brackets. The characters between < and > form the target URI reference.
  4. Everything after the closing > is interpreted as a semicolon-separated parameter list.
  5. Parse that parameter list using the algorithm in Appendix B.3.
  6. If a parameter name occurs more than once and the parameter definition does not allow repetition, keep the first occurrence and ignore later occurrences.
  7. Return each parsed link with its target URI reference, relation type, and target attributes.

Commas and semicolons inside quoted strings do not delimit link-values or parameters. Backslash escaping in quoted strings is handled by Appendix B.4.

B.3. Parsing Parameters (解析参数)

To parse a parameter list:

  1. Split the parameter list on semicolons that are not inside a quoted string.
  2. Ignore an empty item produced by leading, trailing, or repeated semicolons.
  3. For each item, remove leading and trailing optional whitespace.
  4. The parameter name is the token before the first = character. If no = is present, the parameter has an empty value.
  5. Parameter names are compared case-insensitively.
  6. If the value starts with a double quote, parse it as a quoted string using Appendix B.4.
  7. Otherwise, the value extends to the end of the item after optional whitespace is removed.
  8. Store the parameter name and value as a target attribute for the current link-value.

The rel parameter identifies the link relation type. Extension relation types are URI references and registered relation types are tokens.

B.4. Parsing a Quoted String (解析带引号的字符串)

To parse a quoted string:

  1. The value begins with a double quote.
  2. Read characters until an unescaped double quote is found.
  3. When a backslash is encountered, append the following character to the output value and continue.
  4. Characters after the closing double quote are not part of the quoted-string value.
  5. If the closing double quote is absent, treat the value as invalid for this link-value.

This preserves quoted commas, semicolons, and other delimiter characters as data rather than syntax.

Appendix C. Changes from RFC 5988 (与RFC 5988的变化)

本规范与RFC 5988相比的主要变化包括:

  • 澄清了链接上下文和链接目标的定义
  • 更新了注册程序以使用RFC 8126
  • 添加了解析算法(附录B)
  • 澄清了扩展关系类型的使用
  • 更新了对其他规范的引用
  • 改进了示例和说明文本