Header HTTP umum

Header HTTP adalah pasangan kunci-nilai yang dikirim di awal setiap permintaan dan respons. Mereka membawa metadata seperti jenis konten, aturan cache, dan autentikasi. Gunakan lembar ini untuk mengenali header paling umum saat membangun atau men-debug lalu lintas web.

Diperbarui:

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

Catatan

Pertanyaan umum

Apa bedanya header permintaan dan respons?
Header permintaan dikirim klien (browser atau app) ke server; header respons dikembalikan server bersama jawabannya. Beberapa, seperti Content-Type, muncul di kedua sisi.
Apakah nama header HTTP peka huruf besar/kecil?
Tidak. Menurut spesifikasi, nama header tidak peka huruf, jadi Content-Type dan content-type sama saja. Title-Case hanyalah konvensi.
Apa fungsi header Host?
Host memberi tahu server domain mana yang dituju permintaan. Wajib ada di HTTP/1.1 dan memungkinkan satu server menampung banyak situs berdasarkan nama.
Bagaimana cache bekerja dengan header?
Cache-Control menentukan berapa lama respons boleh di-cache; ETag dan If-None-Match membiarkan klien bertanya 'berubah?' dan menerima 304 Not Modified yang ringan.