Intestazioni HTTP comuni

Le intestazioni HTTP sono coppie chiave-valore inviate all'inizio di ogni richiesta e risposta. Trasportano metadati come il tipo di contenuto, le regole di cache e l'autenticazione. Usa questa scheda per riconoscere le intestazioni più frequenti quando crei o fai debug del traffico web.

Aggiornato:

IntestazioneDirezioneScopo
HostrequestIdentifies the server's host and port (from the URL).
User-AgentrequestReports the client software (browser, OS, bot) making the request.
AcceptrequestLists the response media types (MIME) the client can handle.
AuthorizationrequestCarries credentials (token, Basic auth) to authenticate the client.
Content-Typerequest/responseStates the media type of the request or response body.
Content-Lengthrequest/responseGives the size in bytes of the request or response body.
CookierequestSends stored key/value pairs from a previous response back to the server.
Set-CookieresponseServer instructs the client to store a cookie for later requests.
Cache-Controlrequest/responseDirects caching behaviour: no-cache, max-age, private, etc.
ETagresponseOpaque identifier for a resource version, used for revalidation.
If-None-MatchrequestSends an ETag; server returns 304 if the resource is unchanged.
LocationresponsePoints the client to a new URL for redirects (3xx) or created resources.
Access-Control-Allow-OriginresponsePermits a browser to share a response across origins (CORS).
X-Forwarded-ForrequestRecords the client IP as seen through a proxy or load balancer.
RefererrequestIndicates the URL of the page that linked to the requested resource.

Note

Domande frequenti

Qual è la differenza tra intestazione di richiesta e di risposta?
Le intestazioni di richiesta le invia il client (browser o app) al server; quelle di risposta le restituisce il server con la sua risposta. Alcune, come Content-Type, compaiono su entrambi i lati.
I nomi delle intestazioni HTTP fanno distinzione tra maiuscole/minuscole?
No. Secondo la specifica i nomi non sono case-sensitive, quindi Content-Type e content-type sono equivalenti. Il Title-Case è solo una convenzione.
A cosa serve l'intestazione Host?
Host indica al server quale dominio la richiesta mira. È obbligatoria in HTTP/1.1 e consente a un server di ospitare più siti per nome.
Come funziona la cache con le intestazioni?
Cache-Control stabilisce per quanto una risposta può essere memorizzata; ETag e If-None-Match permettono al client di chiedere 'è cambiato?' e ricevere un leggero 304 Not Modified.