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 节。

    ¥Duplicates of age, authorization, content-length, content-type, etag, expires, from, host, if-modified-since, if-unmodified-since, last-modified, location, max-forwards, proxy-authorization, referer, retry-after, server, or user-agent are discarded. To allow duplicate values of the headers listed above to be joined, use the option joinDuplicateHeaders in http.request() and http.createServer(). See RFC 9110 Section 5.3 for more information.

  • set-cookie 始终是数组。重复项被添加到数组中。

    ¥set-cookie is always an array. Duplicates are added to the array.

  • 对于重复的 cookie 标头,值使用 ; 连接。

    ¥For duplicate cookie headers, the values are joined together with ; .

  • 对于所有其他标头,值使用 , 连接。

    ¥For all other headers, the values are joined together with , .