In this lesson you will
- Send and read request and response headers with curl and fetch
- Read Cache-Control and use ETag for a 304 Not Modified response
- Explain how Set-Cookie and Cookie work and set safe cookie flags
Request headers: telling the server about you
httpbin’s /headers address replies with the request headers it received, which makes it a mirror. From curl we sent Accept: application/json and Accept-Language: ar-AE, and the mirror showed those two plus Host and curl’s User-Agent. Accept asks for a format, Accept-Language asks for a language, so a well built API can answer Arabic text to a user in Dubai without a separate address. Content-Type is the matching header when you send a body: it says what the body is, not what you want back.
The browser sends far more by itself. Our live example asked for JSON and added a custom X-Shop header, and the browser added Origin, Sec-Fetch-* hints that describe the request, client hints such as Sec-Ch-Ua-Platform, and its own User-Agent. Origin: null appears because the example runs in a sandboxed frame with no real origin. Some headers, such as Host, Origin and Cookie, are forbidden for JavaScript to set, so a page cannot pretend to be another site.
Console
- Console messages, errors, form data and clicked links appear here.
In headless Chrome 153 on Linux the list had 12 headers, including "Origin": "null", "Sec-Fetch-Mode": "cors" and our "X-Shop": "souq-demo". Your list will differ by browser, system and language settings, which is the point: run it and compare.
{
"headers": {
"Accept": "application/json",
"Accept-Language": "ar-AE",
"Host": "httpbin.org",
"User-Agent": "curl/8.5.0"
}
}Sign in free to read the full lesson
You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.
Unlocks after sign-in:
- 3 more sections with live code examples
- Common mistakes to avoid
- Hands-on coding exercise with automatic checks
- Practice quiz and the graded lesson test
Free forever. No card, no paywall.
Questions people ask
What is the difference between no-cache and no-store?
no-cache allows storing a copy but requires checking with the server before using it, often with an ETag and a cheap 304. no-store forbids keeping any copy at all. Despite the name, no-cache does cache.
Are cookies and localStorage the same thing?
No. Cookies are sent to the server automatically with every matching request and can be HttpOnly. localStorage stays in the browser, is never sent by itself and is always readable by scripts, so it is a poor place for login tokens.
How big can a cookie be?
Browsers guarantee about 4 KB per cookie and limit how many each site may keep. Every cookie is sent with every request to that site, so keep them few and small: store an ID in the cookie and the data on the server.
Why do I still see an old version of a page after an update?
Some cache along the way, the browser or a CDN, kept a copy that its Cache-Control still allows. A hard reload skips the browser cache; a CDN needs a purge or a shorter max-age. Versioned file names such as app.3f9a.js avoid the problem for static files.
Can I make up my own HTTP headers?
Yes, any name works, such as X-Shop in the example. The old X- prefix is no longer required. From a browser, a custom request header triggers a CORS preflight, so the server must allow it in Access-Control-Allow-Headers.
Sources
Facts in this lesson were checked against these official pages on 29 November 2026.
Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.