자주 쓰는 HTTP 헤더

HTTP 헤더는 모든 요청과 응답의 맨 앞에 전송되는 키-값 쌍입니다. 콘텐츠 타입, 캐시 규칙, 인증 같은 메타데이터를 담습니다. 웹 트래픽을 만들거나 디버깅할 때 자주 만나는 헤더를 이 표로 익혀 두세요.

업데이트:

헤더방향용도
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.

참고

자주 묻는 질문

요청 헤더와 응답 헤더의 차이는?
요청 헤더는 클라이언트(브라우저나 앱)가 서버로 보내고, 응답 헤더는 서버가 답변과 함께 돌려줍니다. Content-Type처럼 양쪽에 다 나오는 헤더도 있습니다.
HTTP 헤더 이름은 대소문자를 구분하나요?
아니요. HTTP 명세상 헤더 이름은 대소문자를 구분하지 않습니다. Content-Type과 content-type은 같습니다. Title-Case는 관습일 뿐입니다.
Host 헤더는 무엇을 하나요?
Host는 요청이 어느 도메인을 향하는지 서버에 알립니다. HTTP/1.1에서는 필수이며, 한 서버가 여러 사이트를 이름으로 구분하도록 합니다.
헤더로 캐시는 어떻게 동작하나요?
Cache-Control은 응답을 얼마나 캐시할지 정하고, ETag와 If-None-Match로 클라이언트가 '바뀌었나?'라고 묻고 변함없으면 가벼운 304 Not Modified를 받습니다.