从响应中解析缓存控制头值

时间:2017-10-05 10:46:01

标签: javascript node.js express npm cache-control

我需要解析缓存控制头响应,以便在缓存API响应时使用它。

示例回复标题:

accumarray

我正在使用{"x-backside-transport":"OK OK","connection":"close","transfer-encoding":"chunked","access-control-allow-origin":"*","cache-control":"public, max-age=60","content-type":"application/json","date":"Thu, 05 Oct 2017 10:33:59 GMT","etag":"\"-161458570\"","x-powered-by":"Express","x-global-transaction-id":"429271565"} ,但这似乎每次都失败。

给我错误:console.log("------ CACHE VALUE----"+JSON.stringify(response.headers.cache-control));

但是当它尝试与

相同时
ReferenceError: control is not defined

我能够成功打印出日志值。我错过了什么吗?

1 个答案:

答案 0 :(得分:4)

短划线-不适用于JSON。你可能想尝试解析如下

response.headers["cache-control"]