Перейти к содержимому
Skip to content
← All articles

HTTP Headers: The Complete Guide

HTTP headers are metadata transmitted between a client (browser) and a server with every HTTP request and response. They define how to process data, what content to return, how to cache responses, and much more.

How HTTP Headers Work

Every HTTP request and response consists of three parts: a start line, headers, and body. Headers are name-value pairs separated by line breaks:

GET /api/data HTTP/1.1
Host: example.com
Accept: application/json
Authorization: Bearer eyJhbGci...
User-Agent: Mozilla/5.0

The server responds with its own set of headers:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Cache-Control: max-age=3600
X-Request-Id: abc-123

Types of HTTP Headers

Request Headers

Sent by the client to the server, containing information about the request and the client:

HeaderDescriptionExample
HostServer domain name (required in HTTP/1.1)Host: example.com
AcceptContent types the client acceptsAccept: text/html, application/json
Accept-LanguagePreferred response languagesAccept-Language: en, ru;q=0.8
Accept-EncodingSupported compression algorithmsAccept-Encoding: gzip, br
AuthorizationAuthentication credentialsAuthorization: Bearer token123
CookieCookies previously set by the serverCookie: session=abc; theme=dark
User-AgentClient information (browser, OS)User-Agent: Mozilla/5.0...
RefererURL of the page that initiated the requestReferer: https://google.com/
If-None-MatchETag for conditional requests (caching)If-None-Match: "abc123"
If-Modified-SinceDate for conditional requestsIf-Modified-Since: Mon, 01 Jan 2025...

Response Headers

Sent by the server to the client, containing information about the resource and processing instructions:

HeaderDescriptionExample
Content-TypeMIME type of the returned contentContent-Type: text/html; charset=utf-8
Content-LengthResponse body size in bytesContent-Length: 3842
Content-EncodingResponse body compression algorithmContent-Encoding: gzip
Set-CookieSet a cookie on the clientSet-Cookie: session=abc; HttpOnly; Secure
LocationURL for redirect (3xx) or new resource (201)Location: https://example.com/new
ServerWeb server informationServer: nginx/1.24
ETagResource version identifierETag: "abc123"
Last-ModifiedDate the resource was last modifiedLast-Modified: Mon, 01 Jan 2025...

Caching Headers

Caching is one of the most important performance optimizations. HTTP headers allow precise control over how and where resources are cached:

Cache-Control

The primary cache control header. Supports multiple directives:

Caching Strategies

Static resources (CSS, JS, images) with a hash in the filename:

Cache-Control: public, max-age=31536000, immutable

HTML pages that may be updated:

Cache-Control: no-cache
ETag: "v2.1.0-abc"

Sensitive data (dashboards, API документацию responses with personal information):

Cache-Control: no-store

CORS Headers

Cross-Origin Resource Sharing (CORS) allows a server to specify which domains can access its resources from a browser:

HeaderDescription
Access-Control-Allow-OriginAllowed domain (or * for all)
Access-Control-Allow-MethodsAllowed HTTP methods
Access-Control-Allow-HeadersAllowed request headers
Access-Control-Max-AgePreflight request cache duration
Access-Control-Allow-CredentialsAllow sending cookies

Example configuration for an API:

Access-Control-Allow-Origin: https://myapp.com
Access-Control-Allow-Methods: GET, POST, PUT, DELETE
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Max-Age: 86400

SEO Headers

Some HTTP headers directly affect indexing and SEO:

Common Mistakes

Check your website right now

Check now →
More articles: HTTP
HTTP
HTTP Caching Guide: Cache-Control, ETag, Expires
14.03.2026 · 10 views
HTTP
HTTP Methods Explained: GET, POST, PUT, DELETE and Beyond
16.03.2026 · 16 views
HTTP
HTTP/2 vs HTTP/3: Differences and Performance Comparison
13.03.2026 · 13 views
HTTP
The Complete HTTP Request Lifecycle: From URL to Rendered Page
16.03.2026 · 13 views