request.headers
请求/响应头对象。
标头名称和值的键值对。 标头名称是小写的。
// 打印如下内容:
//
// { 'user-agent': 'curl/7.22.0',
// host: '127.0.0.1:8000',
// accept: '*/*' }
console.log(request.headers);
请参阅 HTTP/2 标头对象。
在 HTTP/2 中,请求路径、主机名、协议和方法表示为带有 :
字符(例如 ':path'
)前缀的特殊标头。
这些特殊的标头将包含在 request.headers
对象中。
必须注意不要无意中修改了这些特殊的标头,否则可能会出现错误。
例如,从请求中删除所有标头将导致发生错误:
removeAllHeaders(request.headers);
assert(request.url); // 失败,因为 :path 标头已被删除
The request/response headers object.
Key-value pairs of header names and values. Header names are lower-cased.
// Prints something like:
//
// { 'user-agent': 'curl/7.22.0',
// host: '127.0.0.1:8000',
// accept: '*/*' }
console.log(request.headers);
In HTTP/2, the request path, host name, protocol, and method are represented as
special headers prefixed with the :
character (e.g. ':path'
). These special
headers will be included in the request.headers
object. Care must be taken not
to inadvertently modify these special headers or errors may occur. For instance,
removing all headers from the request will cause errors to occur:
removeAllHeaders(request.headers);
assert(request.url); // Fails because the :path header has been removed