response.getHeaders()


返回当前发送的头信息的浅拷贝。由于使用了浅拷贝,数组值可以在不额外调用各种与头信息相关的 http 模块方法的情况下被修改。返回对象的键是头信息的名称,值是相应的头信息值。所有头信息名称都是小写。

【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.】

response.getHeaders() 方法返回的对象 不会 原型继承自 JavaScript Object。这意味着常用的 Object 方法,例如 obj.toString()obj.hasOwnProperty() 等未定义,将无法使用

【The object returned by the response.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.】

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

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