标头名称和值中的无效字符处理


【Invalid character handling in header names and values】

HTTP/2 实现对 HTTP 头名称和值中的无效字符处理比 HTTP/1 实现更严格。

【The HTTP/2 implementation applies stricter handling of invalid characters in HTTP header names and values than the HTTP/1 implementation.】

头字段名是 不区分大小写 的,并且在传输时严格作为小写字符串发送。Node.js 提供的 API 允许将头字段名设置为混合大小写的字符串(例如 Content-Type),但在传输时会将其转换为小写(例如 content-type)。

【Header field names are case-insensitive and are transmitted over the wire strictly as lower-case strings. The API provided by Node.js allows header names to be set as mixed-case strings (e.g. Content-Type) but will convert those to lower-case (e.g. content-type) upon transmission.】

头字段名_必须只_包含以下 ASCII 字符之一或多个:a-zA-Z0-9!#$%&'*+-.^_`(反引号)、|~

【Header field-names must only contain one or more of the following ASCII characters: a-z, A-Z, 0-9, !, #, $, %, &, ', *, +, -, ., ^, _, ` (backtick), |, and ~.】

在 HTTP 头字段名称中使用无效字符会导致流被关闭,并报告协议错误。

【Using invalid characters within an HTTP header field name will cause the stream to be closed with a protocol error being reported.】

根据 HTTP 规范的要求,HTTP 头字段值的处理更加宽松,但 不应 包含换行符或回车符,并且 限制为 US-ASCII 字符。

【Header field values are handled with more leniency but should not contain new-line or carriage return characters and should be limited to US-ASCII characters, per the requirements of the HTTP specification.】