Tiêu đề HTTP phổ biến

Tiêu đề HTTP là các cặp khóa-giá trị được gửi ở đầu mỗi yêu cầu và phản hồi. Chúng mang siêu dữ liệu như loại nội dung, quy tắc bộ nhớ đệm và xác thực. Hãy dùng trang này để nhận diện các tiêu đề thường gặp nhất khi xây dựng hay gỡ lỗi lưu lượng web.

Cập nhật:

Tiêu đềHướngMục đích
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.

Ghi chú

Câu hỏi thường gặp

Sự khác biệt giữa tiêu đề yêu cầu và phản hồi là gì?
Tiêu đề yêu cầu do máy khách (trình duyệt hoặc ứng dụng) gửi đến máy chủ; tiêu đề phản hồi do máy chủ gửi lại cùng câu trả lời. Một số như Content-Type xuất hiện ở cả hai phía.
Tên tiêu đề HTTP có phân biệt hoa thường không?
Không. Theo đặc tả, tên tiêu đề không phân biệt hoa thường, nên Content-Type và content-type là một. Title-Case chỉ là quy ước.
Tiêu đề Host dùng để làm gì?
Host cho máy chủ biết yêu cầu nhắm đến tên miền nào. Nó bắt buộc trong HTTP/1.1 và cho phép một máy chủ lưu nhiều trang web theo tên.
Bộ nhớ đệm hoạt động với tiêu đề như thế nào?
Cache-Control quy định phản hồi được lưu cache bao lâu; ETag và If-None-Match giúp máy khách hỏi 'có thay đổi?' và nhận mã nhẹ 304 Not Modified nếu chưa đổi.