Javascript: Headers

fetch("http://localhost", { method: "HEAD" }).then((res) =>
  res.headers.forEach((hVal, hKey) => {
    console.log(hKey, hVal);
  })
);
accept-ranges bytes
content-length 615
content-type text/html
date Fri, 14 Oct 2022 03:14:20 GMT
etag "62d6ba27-267"
last-modified Tue, 19 Jul 2022 14:05:27 GMT
server nginx/1.23.1
fetch("http://localhost", { method: "HEAD" }).then((res) => {
  for (h of res.headers.entries()) {
    console.log(h);
  }
});
(2) ['accept-ranges', 'bytes']
(2) ['content-length', '615']
(2) ['content-type', 'text/html']
(2) ['date', 'Fri, 14 Oct 2022 03:14:20 GMT']
(2) ['etag', '"62d6ba27-267"']
(2) ['last-modified', 'Tue, 19 Jul 2022 14:05:27 GMT']
(2) ['server', 'nginx/1.23.1']
fetch("http://localhost:8080", { method: "HEAD" }).then((res) =>
  console.log(res.headers.get("content-type"))
);
text/html

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *