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.
| Intestazione | Direzione | Scopo |
|---|---|---|
| Host | request | Identifies the server's host and port (from the URL). |
| User-Agent | request | Reports the client software (browser, OS, bot) making the request. |
| Accept | request | Lists the response media types (MIME) the client can handle. |
| Authorization | request | Carries credentials (token, Basic auth) to authenticate the client. |
| Content-Type | request/response | States the media type of the request or response body. |
| Content-Length | request/response | Gives the size in bytes of the request or response body. |
| Cookie | request | Sends stored key/value pairs from a previous response back to the server. |
| Set-Cookie | response | Server instructs the client to store a cookie for later requests. |
| Cache-Control | request/response | Directs caching behaviour: no-cache, max-age, private, etc. |
| ETag | response | Opaque identifier for a resource version, used for revalidation. |
| If-None-Match | request | Sends an ETag; server returns 304 if the resource is unchanged. |
| Location | response | Points the client to a new URL for redirects (3xx) or created resources. |
| Access-Control-Allow-Origin | response | Permits a browser to share a response across origins (CORS). |
| X-Forwarded-For | request | Records the client IP as seen through a proxy or load balancer. |
| Referer | request | Indicates the URL of the page that linked to the requested resource. |
Note
- I nomi delle intestazioni non distinguono maiuscole/minuscole; per convenzione si scrivono in Title-Case (es. Content-Type).
- Le intestazioni di richiesta descrivono il client; quelle di risposta descrivono la risposta del server.
- Il browser imposta molte intestazioni (come Host e Referer) automaticamente: non alterarle.
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.