RFC 5988 是否允许在 HTTP Link header 中使用空格?
Does RFC 5988 allow whitespace in the HTTP Link header?
RFC 5988 的第 5 节定义 Link header 的语法如下:
Link = "Link" ":" #link-value
link-value = "<" URI-Reference ">" *( ";" link-param )
本规范使用 RFC 822 中定义的扩充 Backus-Naur 形式 (BNF)。
如果正确理解 BNF,规范不允许分号 (;
) 和 link-param
之间有空格。但是,在第 5 节中出现的示例中,两个元素之间有空格:
Link: <http://example.com/TheBook/chapter2>; rel="previous";
title="previous chapter"
Link: </>; rel="http://example.net/foo"
我还在 Link header 和 Github 的 API 中观察到空白,我认为这是更多 standard-compliant APIs:
$ curl -s -I https://api.github.com/users/mitsuhiko/repos
...
Link: <https://api.github.com/user/7396/repos?page=2>; rel="next", <https://api.github.com/user/7396/repos?page=7>; rel="last"
空格应该是允许的吗?除了这些例子之外,我找不到任何可以提供证据的东西。
这是允许的; RFC 5988 使用 RFC 2616 定义的 ABNF,它对线性白色 space 有特殊规则。见 https://www.greenbytes.de/tech/webdav/rfc5988.html#rfc.section.2.p.2 and https://www.greenbytes.de/tech/webdav/rfc2616.html#rfc.section.2.1:
The grammar described by this specification is word-based. Except
where noted otherwise, linear white space (LWS) can be included
between any two adjacent words (token or quoted-string), and between
adjacent words and separators, without changing the interpretation of
a field. At least one delimiter (LWS and/or separators) MUST exist
between any two tokens (for the definition of "token" below), since
they would otherwise be interpreted as a single token.
FWIW,无论如何,RFC 5988 几个月前就已经过时了;请参阅 RFC 8288 (https://www.greenbytes.de/tech/webdav/rfc8288.html) 了解最新和最好的(特别是第 3 节)。
RFC 5988 的第 5 节定义 Link header 的语法如下:
Link = "Link" ":" #link-value
link-value = "<" URI-Reference ">" *( ";" link-param )
本规范使用 RFC 822 中定义的扩充 Backus-Naur 形式 (BNF)。
如果正确理解 BNF,规范不允许分号 (;
) 和 link-param
之间有空格。但是,在第 5 节中出现的示例中,两个元素之间有空格:
Link: <http://example.com/TheBook/chapter2>; rel="previous";
title="previous chapter"
Link: </>; rel="http://example.net/foo"
我还在 Link header 和 Github 的 API 中观察到空白,我认为这是更多 standard-compliant APIs:
$ curl -s -I https://api.github.com/users/mitsuhiko/repos
...
Link: <https://api.github.com/user/7396/repos?page=2>; rel="next", <https://api.github.com/user/7396/repos?page=7>; rel="last"
空格应该是允许的吗?除了这些例子之外,我找不到任何可以提供证据的东西。
这是允许的; RFC 5988 使用 RFC 2616 定义的 ABNF,它对线性白色 space 有特殊规则。见 https://www.greenbytes.de/tech/webdav/rfc5988.html#rfc.section.2.p.2 and https://www.greenbytes.de/tech/webdav/rfc2616.html#rfc.section.2.1:
The grammar described by this specification is word-based. Except where noted otherwise, linear white space (LWS) can be included between any two adjacent words (token or quoted-string), and between adjacent words and separators, without changing the interpretation of a field. At least one delimiter (LWS and/or separators) MUST exist between any two tokens (for the definition of "token" below), since they would otherwise be interpreted as a single token.
FWIW,无论如何,RFC 5988 几个月前就已经过时了;请参阅 RFC 8288 (https://www.greenbytes.de/tech/webdav/rfc8288.html) 了解最新和最好的(特别是第 3 节)。