Menu
Request headers
“The extra information a client sends along with a request.”
After the first line come headers: Name: value pairs, one per line, ending with an empty line.
1GET /api/profile HTTP/1.1
2Host: api.example.com
3Accept: application/json
4Accept-Language: nl, en;q=0.8
5Authorization: Bearer eyJhbGciOi...Header names are case-insensitive: Accept and accept are the same.
Headers you’ll see all the time#
| Header | Example | Tells the server… |
|---|---|---|
Host | api.example.com | which website you want (one server can host many). Required in HTTP/1.1 |
User-Agent | curl/8.7.1 | what software is asking |
Accept | application/json | what formats you can handle |
Accept-Language | nl, en;q=0.8 | preferred languages (q = preference from 0 to 1) |
Content-Type | application/json | the format of the body you’re sending |
Authorization | Bearer <token> | who you are |
Cookie | session=abc123 | cookies the server set earlier |
Cookies: how “stateless” HTTP remembers you#
Remember that HTTP is stateless. Cookies fix that:
- You log in. The server answers with a
Set-Cookieheader:httpHTTP/1.1 200 OK Set-Cookie: session=abc123; HttpOnly; Secure; SameSite=Lax - From now on, the browser adds that cookie to every request to the same site:http
1GET /account HTTP/1.1 2Host: shop.example.com 3Cookie: session=abc123 - The server looks up
abc123and knows it’s you.
Caution
Anyone who gets that cookie value is you as far as the server knows. HttpOnly hides it from JavaScript and Secure sends it only over HTTPS. Use both for session cookies.
Sending headers yourself#
curl -H "Accept: application/json" -H "Accept-Language: nl" https://httpbin.org/headershttpbin.org/headers echoes back the headers it received, so you can see exactly what was sent:
1{
2 "headers": {
3 "Accept": "application/json",
4 "Accept-Language": "nl",
5 "Host": "httpbin.org",
6 "User-Agent": "curl/8.7.1"
7 }
8}Answer these 3 questions to commit this byte to your learning path.
Reset. This byte isn't committed any more. Answer the questions again to commit it.
$ git commit -m "learn(http): Request headers"
[main d6fa748] learn(http): Request headers
1 byte changed, 3 insertions(+)
See it on your path Already committed . Try the questions again any time, it won't undo anything. To uncommit it and start over: