Whether you are interviewing for a backend, frontend, or full-stack role, HTTP headers come up constantly in API design, caching, security, and debugging discussions. Here are 10 of the most common interview questions on HTTP request headers along with clear, practical answers.
1. What is the Host header, and why is it required in HTTP/1.1?
Answer:
The Host header specifies the domain name (and optional port number) of the server being requested—for example, Host: api.example.com.
It is mandatory in HTTP/1.1 because a single IP address and web server/reverse proxy (such as Nginx) often hosts multiple websites or applications (virtual hosting). Without the Host header, the server wouldn't know which domain or virtual host is being targeted when multiple domains share the same IP.
![]()
2. What is the difference between Content-Type and Accept?
Answer:
Both headers deal with media types (MIME types), but they apply to opposite directions of the request/response cycle:
Content-Typetells the server the format of the request body being sent by the client (e.g.,Content-Type: application/json).Accepttells the server what response format(s) the client can handle or prefers to receive (e.g.,Accept: application/json, text/plain;q=0.9).
Interview tip: A GET request typically has no body, so setting Content-Type on a GET request is usually unnecessary or ignored.
3. How is the Authorization header used, and what are common schemes?
Answer:
The Authorization header sends client credentials or tokens to prove identity or permission to access a protected resource. Common schemes include:
- Bearer: Most common for OAuth 2.0 access tokens and JWTs (
Authorization: Bearer <token>). - Basic: Sends
username:passwordencoded in Base64 (Authorization: Basic <base64_string>). Base64 is encoding, not encryption, so Basic auth should only be used over HTTPS.
4. How does the Cookie header work in HTTP requests?
Answer:
When a server wants the client to store data (such as a session ID), it sends a Set-Cookie header in the response. On subsequent requests matching the cookie's domain, path, and security rules, the client (such as a browser) automatically attaches saved cookies in a single Cookie request header formatted as key-value pairs separated by semicolons:
Cookie: session_id=xyz123; theme=dark
5. What is the User-Agent header, and how do servers use it?
Answer:
The User-Agent header identifies the client software making the request—typically including browser engine, OS, or app/library name and version (e.g., curl/8.7.1 or a browser string).
Servers use it for analytics, logging, bot/crawler detection, and occasionally feature or layout adjustments. However, because clients can easily spoof or omit User-Agent, it should never be trusted for security or authentication.
6. How do Cache-Control, If-None-Match, and If-Modified-Since work together?
Answer:
These headers optimize performance and bandwidth by controlling caching and revalidation:
Cache-Control(request): Tells intermediate caches or origin servers how the client wants caching handled—for example,Cache-Control: no-cache(revalidate with the origin before using a cached copy) orCache-Control: max-age=0.If-None-Match: Sends theETagvalue from a previous response. If the resource'sETagstill matches on the server, it returns304 Not Modifiedwithout resending the body.If-Modified-Since: Sends theLast-Modifiedtimestamp from a previous response; if the resource hasn't changed since that time, the server can respond with304 Not Modified.
7. What is the Origin header, and how does it relate to CORS?
Answer:
The Origin header indicates the scheme, host, and port of the origin that initiated a cross-origin request or POST request (e.g., Origin: [https://app.example.com](https://app.example.com))—notice it does not include the path.
Browsers automatically include Origin on cross-origin requests and preflight (OPTIONS) checks so the server can evaluate Cross-Origin Resource Sharing (CORS) policies and respond with appropriate Access-Control-Allow-* headers.
8. What is the difference between Origin and Referer?
Answer:
Both provide context about where a request came from, but they differ in scope and behavior:
Origincontains only the origin (scheme://host:port) and is primarily used for CORS and CSRF/origin checks.Referer(historically misspelled in the HTTP spec) contains the full or partial URL of the page from which the request originated, subject to the activeReferrer-Policy. For example, clicking a link or loading an image on[https://blog.example.com/posts/http-headers](https://blog.example.com/posts/http-headers)may sendReferer: [https://blog.example.com/posts/http-headers](https://blog.example.com/posts/http-headers).
Because Referer can leak sensitive query parameters or internal URLs to third-party sites, strict referrer policies often strip paths or omit the header cross-origin.
9. How do Accept-Encoding and Accept-Language support content negotiation?
Answer:
Content negotiation lets the client advertise capabilities and preferences so the server can return the best representation:
Accept-Encodinglists compression algorithms the client can decode (such asgzip,brfor Brotli, orzstd). If supported, the server compresses the body and setsContent-Encodingon the response, saving bandwidth.Accept-Languagespecifies preferred natural languages and regional locales with optional quality weights (e.g.,Accept-Language: en-US,en;q=0.9,ja;q=0.8).
10. What is the Range header used for?
Answer:
The Range header asks the server to return only a specific byte range (or set of ranges) of a resource rather than the entire file—for example:
Range: bytes=0-1023
If the server supports range requests for that resource, it typically responds with 206 Partial Content and a Content-Range header. This powers resumable downloads, video/audio seeking, and parallel chunk downloading of large files.
Quick Reference Summary
| Header | Primary Role | Typical Example |
|---|---|---|
Host |
Target domain/port on server | Host: api.example.com |
Content-Type |
Format of request body | Content-Type: application/json |
Accept |
Preferred response format | Accept: application/json |
Authorization |
Auth credentials or bearer token | Authorization: Bearer <token> |
Cookie |
Stored cookies sent back to server | Cookie: sid=abc123 |
User-Agent |
Client software identification | User-Agent: Mozilla/5.0 |
Cache-Control |
Cache directives | Cache-Control: no-cache |
If-None-Match |
Conditional fetch using ETag |
If-None-Match: "v1-etag" |
Origin |
Requesting origin for CORS/security | Origin: [https://example.com](https://example.com) |
Range |
Partial byte range of a resource | Range: bytes=500-999 |