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

Rah*_*rma 0 javascript cache-control node.js npm express

我需要解析缓存控制标头响应以通过缓存 API 响应来使用它。

示例响应头:

{"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"}
Run Code Online (Sandbox Code Playgroud)

我正在使用,console.log("------ CACHE VALUE----"+JSON.stringify(response.headers.cache-control));但这似乎每次都失败。

给我错误: ReferenceError: control is not defined

但是当它尝试与

console.log("------ CACHE VALUE----"+JSON.stringify(response.headers.connection));
Run Code Online (Sandbox Code Playgroud)

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

小智 5

Dash-不适用于 JSON。您可能想尝试像下面这样解析

response.headers["cache-control"]
Run Code Online (Sandbox Code Playgroud)