原始标头


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