Nodejs Parse fetch response containing object [Symbol(map)]

大城市里の小女人 提交于 2020-05-12 20:35:38

问题


I do not know how to access the parameter x-error-detail-header.

I receive this response headers from a request using node-fetch npm package:

     Headers {
      [Symbol(map)]: 
  { 'content-type': [ 'text/xml' ],
 date: [ 'Fri, 27 Apr 2018 09:46:56 GMT' ],
 'retry-after': [ '51184' ],
 server: [ 'xxxxx' ],
 'x-error-detail-header': [ 'Account Over Rate Limit' ],
 'x-x-error-code': [ 'ERR_403_DEVELOPER_OVER_RATE' ],
 'x-x-responder': [ 'xxxxxxx.com' ],
 'x-plan-qps-allotted': [ '2' ],
 'x-plan-qps-current': [ '1' ],
 'x-plan-quota-allotted': [ '50' ],
 'x-plan-quota-current': [ '51' ],
 'x-plan-quota-reset': [ 'Saturday, April 28, 2018 12:00:00 AM GMT' ],
 'content-length': [ '28' ],
 connection: [ 'Close' ] } }

My problem is that I do not know how to access the parameters that are inside [Symbol(map)] object.


回答1:


It is a Headers object. It has e.g. get and forEach methods. For example:

getDownload = async (url) => {
    const response = await fetch(url);
    console.log(response.headers.get('content-type'));
    return {
        name: response.headers.get('Content-Disposition'),
        length: response.headers.get('content-length')
    }
}

Note the case insensitivity.



来源:https://stackoverflow.com/questions/50060008/nodejs-parse-fetch-response-containing-object-symbolmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!