HTTP 메시지는 다음과 같은 세 가지 주요 요소로 구성됩니다:
1. 시작 라인
GET /index.html HTTP/1.1
)HTTP/1.1 200 OK
)Host 헤더
Host: www.example.com:8080
User-Agent 헤더
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/91.0.4472.124 Safari/537.36
Referer 헤더
Referer: http://www.google.com
Authorization 헤더
Authorization: Basic <Base64-encoded username:password>
Server 헤더
Server: Apache/2.4.1 (Unix)
Allow 헤더
Allow: GET, POST, OPTIONS
Retry-After 헤더
Retry-After: Fri, 23 Aug 2024 09:00:00 GMT
Retry-After: 120
Location 헤더
Location: http://www.example.com/new-resource
WWW-Authenticate 헤더
WWW-Authenticate: Basic realm="Access to the site"
Date 헤더
Date: Tue, 25 Jan 2025 12:00:00 GMT
Connection 헤더
Connection: keep-alive
Connection: close
Content-Length 헤더
Content-Length: 348
Content-Type 헤더
Content-Type: text/html; charset=UTF-8
Content-Encoding 헤더
Content-Encoding: gzip
Content-Language 헤더
Content-Language: en-US
캐시란?
캐시의 종류
캐시 신선도 검사
Expires
또는 Cache-Control: max-age
로 유효 기간 설정.쿠키란?
쿠키의 주요 속성
Domain
: 쿠키가 적용될 도메인.Path
: 쿠키가 적용될 경로.Secure
: HTTPS 연결에서만 전송.HttpOnly
: 자바스크립트를 통한 접근 차단.세션 인증
콘텐츠 협상이란?
관련 HTTP 헤더
Accept
: 선호하는 미디어 타입.Accept-Language
: 선호하는 언어.Accept-Encoding
: 선호하는 압축 방식.Q 값 우선순위
Accept-Language: ko-KR, en-US;q=0.8, en;q=0.5
200 OK
: 요청 성공.401 Unauthorized
: 인증 필요.304 Not Modified
: 캐시된 데이터 그대로 사용 가능.503 Service Unavailable
: 일시적 서비스 중단.HTTP 헤더는 클라이언트와 서버 간의 요청과 응답을 더욱 효율적으로 수행하며, 캐싱, 쿠키, 콘텐츠 협상 등 다양한 기술의 기반이 됩니다. 각 헤더의 역할을 잘 이해하고 활용하면 더 나은 네트워크 설계를 할 수 있습니다.