message.headers


请求/响应头对象。

【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); 

原始头中的重复项处理方法如下,具体取决于头名称:

【Duplicates in raw headers are handled in the following ways, depending on the header name:】

  • 会丢弃 ageauthorizationcontent-lengthcontent-typeetagexpiresfromhostif-modified-sinceif-unmodified-sincelast-modifiedlocationmax-forwardsproxy-authorizationrefererretry-afterserveruser-agent 的重复项。要允许上述列出的头部重复值被合并,请在 http.request()http.createServer() 中使用选项 joinDuplicateHeaders。更多信息参见 RFC 9110 第 5.3 节。
  • set-cookie 总是一个数组。重复项会被添加到数组中。
  • 对于重复的 cookie 头,值会使用 ; 连接在一起。
  • 对于所有其他头部,值将使用 , 连接在一起。