原始标头


【Raw headers】

在某些 API 中,除了对象格式外,头信息还可以作为原始扁平数组传递或访问,以保留顺序和重复键的细节,以匹配原始传输格式。

【In some APIs, in addition to object format, headers can also be passed or accessed as a raw flat array, preserving details of ordering and duplicate keys to match the raw transmission format.】

在这种格式中,键和值在同一个列表中。它_不是_元组列表。因此,偶数位是键,奇数位是对应的值。重复的标题不会合并,因此每个键值对会单独出现。

【In this format the keys and values are in the same list. It is not a list of tuples. So, the even-numbered offsets are key values, and the odd-numbered offsets are the associated values. Duplicate headers are not merged and so each key-value pair will appear separately.】

这在某些情况下可能很有用,例如代理服务器,需要将现有的头信息完全按接收到的方式转发,或者当头信息已经以原始格式可用时,可用于性能优化。

【This can be useful for cases such as proxies, where existing headers should be exactly forwarded as received, or as a performance optimization when the headers are already available in raw format.】

const rawHeaders = [
  ':status',
  '404',
  'content-type',
  'text/plain',
];

stream.respond(rawHeaders);