Response: headers property
The headers property is the response headers, a Headers object.
Value
A Headers.
- Read-only; assigning to it throws
TypeError. - Header names are case-insensitive:
get('content-type')andget('CONTENT-TYPE')give the same value. - When the server returns several headers with the same name,
get()gives one string joined with,. Read multipleSet-Cookieheaders separately withgetSetCookie(). - For a response you create with
new Response(), it isinit.headers, with a defaultContent-Typeadded based on the body when none is given.
Examples
js
async function main() {
const res = await fetch('https://httpbin.org/get');
console.log(res.headers.get('content-type'));
console.log(res.headers.get('CONTENT-TYPE'));
}
main();Result: Both lines print application/json.
Differences from the web
Same as on the web.
See also
Headers: methods for reading and iterating headers