Mga karaniwang HTTP header

Ang mga HTTP header ay mga key-value pair na ipinapadala sa simula ng bawat request at response. Dala nito ang metadata tulad ng uri ng content, caching rules, at authentication. Gamitin ang sheet na ito para makilala ang pinakakaraniwang header kapag bumubuo o nagde-debug ng web traffic.

Na-update:

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

Tala

Mga madalas itanong

Ano ang pagkakaiba ng request header at response header?
Ang mga request header ay ipinapadala ng client (browser o app) sa server; ang response header ay ibinabalik ng server kasama ang sagot. Ang ilan, tulad ng Content-Type, ay lumalabas sa parehong panig.
Ang mga pangalan ba ng HTTP header ay case-sensitive?
Hindi. Ayon sa spec, ang mga pangalan ng header ay hindi case-sensitive, kaya ang Content-Type at content-type ay iisá lang. Ang Title-Case ay konbensyon lang.
Para saan ang Host header?
Sinasabi ng Host sa server kung aling domain ang tinutukoy ng request. Ito ay required sa HTTP/1.1 at nagpapahintulot sa isang server na mag-host ng maraming site ayon sa pangalan.
Paano gumagana ang caching gamit ang mga header?
Tinatakda ng Cache-Control kung gaano katagal pwedeng i-cache ang isang response; pinapayagan ng ETag at If-None-Match ang client na magtanong 'nagbago ba?' at tumanggap ng magaang 304 Not Modified.