4.7. 规定 HTTP Header Field
4.7. 规定 HTTP Header Field (Specifying HTTP Header Fields)
application 经常需要定义新的 HTTP header field. 当它们这样做时, MUST 按 [HTTP] Section 16.3 中的过程, 在 "Hypertext Transfer Protocol (HTTP) Field Name Registry" 中注册这些 field.
[STRUCTURED-FIELDS] 提供了一种定义 header field value 的标准化方式, 使其更容易解析和处理. application 在定义新 header field 时 SHOULD 使用 Structured Fields.
定义 header field 时, application 需要考虑:
-
header field name SHOULD 具有描述性, 并遵循 [HTTP] Section 16.3.1 中的命名约定.
-
header field SHOULD NOT 使用 "X-" prefix, 如 [RFC6648] 所述.
-
header field 的 value syntax SHOULD 被清楚规定. 推荐使用 [STRUCTURED-FIELDS].
-
header field 的 semantics SHOULD 被清楚解释, 包括何时应发送以及如何解释.
-
application SHOULD 考虑 header field 应为 hop-by-hop 还是 end-to-end. 大多数 application-defined header field 应为 end-to-end.
-
application SHOULD 规定如果 header field 在 message 中出现多次会发生什么.
-
application SHOULD 规定该 header field 用于 request, response, 或两者都用.
application SHOULD 尽可能复用现有 header field, 而不是定义新的. 例如, 如果 application 需要标识所发送 content 的类型, 则应使用 Content-Type, 而不是定义新的 header field.
复用现有 header field 时, application MUST 尊重其已定义的 semantics 和 syntax.