Yleisiä HTTP-otsikoita

HTTP-otsikot ovat avain-arvo-pareja, jotka lähetetään jokaisen pyynnön ja vastauksen alussa. Ne kuljettavat metatietoja, kuten sisältötyypin, välimuistisäännöt ja todennuksen. Käytä tätä taulukkoa tunnistaaksesi yleisimmät otsikot verkkoliikenteen luomisessa tai virheenkorjauksessa.

Päivitetty:

OtsikkoSuuntaTarkoitus
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.

Huomautukset

Usein kysytyt kysymykset

Mitä eroa on pyynnön ja vastauksen otsikoilla?
Pyynnön otsikot lähettää asiakas (selain tai sovellus) palvelimelle; vastauksen otsikot palauttaa palvelin vastauksensa mukana. Jotkin, kuten Content-Type, esiintyvät molemmilla puolilla.
Ovatko HTTP-otsikoiden nimet kirjainkoosta riippuvaisia?
Ei. Määrityksen mukaan otsikoiden nimet eivät riipu kirjainkoosta, joten Content-Type ja content-type tarkoittavat samaa. Title-Case on vain konventio.
Mitä Host-otsikko tekee?
Host kertoo palvelimelle, mitä verkkotunnusta pyyntö koskee. Se on pakollinen HTTP/1.1:ssä ja sallii yhden palvelimen isännöidä useita sivustoja nimen perusteella.
Miten välimuisti toimii otsikoiden kanssa?
Cache-Control määrittää, kuinka kauan vastaus voidaan välimuistittaa; ETag ja If-None-Match antavat asiakkaan kysyä 'muuttuiko?' ja saada kevyt 304 Not Modified.