Hosting glossaryAn HTTP header is a line of information sent with a web request or response, such as the content type, caching rules, or security policies.
Every HTTP request and response is made of two parts: headers and a body. The body is the content itself, such as the HTML of a page or the bytes of an image. The headers come first and describe it: what kind of content it is, how long it may be cached, whether it is compressed, which cookies go with it, and what the browser is allowed to do with it. Each header is a single line in the form Name: value, and header names are not case-sensitive.
Request headers
Sent by the browser (or a bot) with each request. Common ones:
Host: the domain being requested, which lets one server host many sites.User-Agent: the browser or bot making the request.Accept-Encoding: the compression formats the client understands, such as gzip and Brotli.Cookie: cookies previously set by the site, including WordPress login cookies.Referer: the page the visitor came from (the misspelling is in the original specification).
Response headers
Sent by the server with its answer:
Content-Type: what the body is, for exampletext/html; charset=UTF-8.Cache-Control: whether and for how long browsers and CDNs may cache the response.Content-Encoding: how the body was compressed.Set-Cookie: cookies for the browser to store.Location: where to go next, used with redirects.X-Robots-Tag: indexing rules such asnoindex, useful for PDFs and other files that cannot carry a meta robots tag.
Security headers
Strict-Transport-Security(HSTS): tells browsers to use HTTPS only.Content-Security-Policy: limits where scripts, styles, and other resources may load from, a strong defense against cross-site scripting.X-Content-Type-Options: nosniff: stops browsers guessing a file's type.X-Frame-Options, or the CSPframe-ancestorsdirective: controls whether other sites can embed your pages in frames, which prevents clickjacking.Referrer-PolicyandPermissions-Policy: control what referrer data is shared and which browser features pages may use.
The older X-XSS-Protection header is obsolete; modern browsers ignore it.
How to check headers
In the browser, open developer tools, go to the Network tab, reload, and click a request. From the command line, curl -I https://example.com/ prints the response headers.
Setting headers on a WordPress site
Headers can be set in the web server configuration (Apache's .htaccess with mod_headers, or NGINX's add_header), at the CDN, by a plugin, or in PHP through the send_headers hook. Server or CDN level is usually best, because it also covers images and other static files that never pass through WordPress.
Two mistakes come up often. Caching headers that are too aggressive can serve logged-in or cart pages to the wrong visitor. And a Content Security Policy written without testing can break scripts across the site; roll it out with Content-Security-Policy-Report-Only first and switch to enforcement once the reports are clean.
Source: MDN Web Docs, HTTP headers.