Skip to main content

5. The Link Header Field (Link 头部字段)

Link 头部字段提供了一种在 HTTP 头部中序列化链接的方法。

概述

语义等价性:

  • 等价于 HTML <LINK> 元素
  • 等价于 Atom atom:link 源级别元素

ABNF 语法

Link           = "Link" ":" #link-value
link-value = "<" URI-Reference ">" *( ";" link-param )
link-param = ( ( "rel" "=" relation-types )
| ( "anchor" "=" <"> URI-Reference <"> )
| ( "rev" "=" relation-types )
| ( "hreflang" "=" Language-Tag )
| ( "media" "=" ( MediaDesc | ( <"> MediaDesc <"> ) ) )
| ( "title" "=" quoted-string )
| ( "title*" "=" ext-value )
| ( "type" "=" ( media-type | quoted-mt ) )
| ( link-extension ) )
relation-types = relation-type
| <"> relation-type *( 1*SP relation-type ) <">
relation-type = reg-rel-type | ext-rel-type
reg-rel-type = LOALPHA *( LOALPHA | DIGIT | "." | "-" )
ext-rel-type = URI

组成部分

5.1. Target IRI (目标 IRI)

  • 在尖括号 <> 中作为 URI-Reference 传达
  • 相对 URIs 按照 RFC 3986 第 5 节解析
  • 不应用来自消息内容的基础 IRI

5.2. Context IRI (上下文 IRI)

  • 默认: 请求资源的 IRI
  • 覆盖: 使用 anchor 参数
  • 可以指定片段或第三方资源
  • 相对 URIs 按照 RFC 3986 解析

5.3. Relation Type (关系类型)

  • 使用 rel 参数传达
  • 必须 (MUST) 存在
  • 支持多个关系类型 (空格分隔)
  • 扩展关系类型必须是绝对 URI

5.4. Target Attributes (目标属性)

标准属性:

  • hreflang - 目标资源语言
  • media - 目标媒体类型
  • title - 人类可读的链接标题
  • title* - 编码的标题 (RFC 5987)
  • type - 目标媒体类型提示
  • rev - 反向关系 (已弃用)

5.5. Examples (示例)

Link: `http://example.com/TheBook/chapter2`; rel="previous";
title="previous chapter"

Link: </>; rel="http://example.net/foo"

Link: </terms>; rel="copyright"; anchor="#foo"

相关: