outgoingMessage.getHeaders()


返回当前传出标头的浅拷贝。 由于使用了浅拷贝,因此无需额外调用各种与标头相关的 HTTP 模块方法即可更改数组值。 返回对象的键是标头名称,值是相应的标头值。 所有标头名称均为小写。

outgoingMessage.getHeaders() 方法返回的对象不是原型继承自 JavaScript Object。 这意味着 obj.toString()obj.hasOwnProperty() 等典型的 Object 方法没有定义,将不起​​作用。

outgoingMessage.setHeader('Foo', 'bar');
outgoingMessage.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);

const headers = outgoingMessage.getHeaders();
// headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }

Returns a shallow copy of the current outgoing headers. Since a shallow copy is used, array values may be mutated without additional calls to various header-related HTTP module methods. The keys of the returned object are the header names and the values are the respective header values. All header names are lowercase.

The object returned by the outgoingMessage.getHeaders() method does not prototypically inherit from the JavaScript Object. This means that typical Object methods such as obj.toString(), obj.hasOwnProperty(), and others are not defined and will not work.

outgoingMessage.setHeader('Foo', 'bar');
outgoingMessage.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);

const headers = outgoingMessage.getHeaders();
// headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }