response.getHeaders()
- 返回: <Object>
返回当前传出标头的浅拷贝。 由于使用了浅拷贝,因此无需额外调用各种与标头相关的 http 模块方法即可更改数组值。 返回对象的键是标头名称,值是相应的标头值。 所有标头名称均为小写。
response.getHeaders()
方法返回的对象通常不是从 JavaScript Object
继承的原型。
这意味着典型的 Object
方法,例如 obj.toString()
、obj.hasOwnProperty()
和其他方法没有定义并且不会起作用。
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'] }
- Returns: <Object>
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 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'] }