Network/HTTP
[모든 개발자를 위한 HTTP 웹 기본 지식 강의] 일반헤더 개념설명
by ymkim
2023. 4. 25.
✔ HTTP 헤더
#1: RequestGET /search?q=hello&hl=ko HTTP/1.1Host: www.google.com #header#2: ResponseHTTP/1.1 200 OKContent-Type: text/html;charset=UTF-8Content-Length: 3423 #header<html> <body>...</body></html>
- header-field = field-name “:” OWS field-value OWS (OWS: 띄어쓰기 허용)
- field-name은 대소문자 구분 없음
HTTP 헤더의 용도
- HTTP 전송에 필요한 모든 부가정보
- 메시지 바디 내용, 크기, 압축, 인증, 요청 클라이언트, 서버 정보, 캐시 관리정보
- 표준 헤더가 너무 많음
- 필요시 임의의 헤더 추가 가능
HTTP 헤더
분류 - RFC2616(과거)
- 헤더 분류
- General 헤더: 메시지 전체에 적용되는 정보, 예) Connection: close
- Request 헤더: 요청 정보, 예) User-Agent: Mozila/5.0 (Macintosh; ..)
- Response 헤더: 응답 정보, 예) Server: Apache
- Entity 헤더: 엔티티 바디 정보, 예) Content-Type: text/html, Content-Length: 3423
HTTP BODY
message body - RFC2616(과거)
HTTP/1.1 200 OKContent-Type: text/html;charset=UTF-8 #엔티티 헤더Content-Length: 3423 #엔티티 헤더<html> <body>...</body> #엔티티 본문</html>
- 메시지 본문(message body)은 엔티티 본문(entity body)을 전달하는데 사용
- 엔티티 본문은 요청이나 응답에서 실제 전달할 데이터
- 메시지 본문 안에 엔티티 본문을 포함시켜 전달 (과거에)
- 엔티티 헤더는 엔티티 본문의 데이터를 해석할 수 있는 정보 제공
- 데이터 유형(html, json), 데이터 길이, 압축 정보 등등
1999년 RFC2616 폐기 -> RFC723x 변화
- 엔티티(Entity) -> 표현(Representation)
- 엔티티라는 용어 대신 -> 표현이라는 용어로 대체됨
- Representation = representation Metadata + Representation Data
- 표현 =표현 메타데이터 + 표현 데이터
HTTP BODY
message body - RFC7230(최신)
HTTP/1.1 200 OKContent-Type: text/html;charset=UTF-8 #표현 헤더Content-Length: 3423 #표현 헤더<html> <body>...</body> #표현 데이터</html>
- 메시지 본문(message body)을 통해 표현 데이터 전달
- 메시지 본문 = 페이로드(payload)
- 표현은 요청이나 응답에서 전달할 실제 데이터
- 표현 헤더는 표현 데이터 를 해석할 수 있는 정보 제공
- 데이터 유형(html, json), 데이터 길이, 압축 정보 등등
- 참고: 표현 헤더는 표현 메타데이터와, 페이로드 메시지를 구분해야 한다
✔ 표현
HTTP/1.1 200 OKContent-Type: text/html;charset=UTF-8 #표현 헤더Content-Length: 3423<html> <body>...</body> #표현 데이터</html>
- Content-Type: 표현 데이터 형식
- Content-Encoding: 표현 데이터 압축 방식
- Content-Language: 표현 데이터의 자연 언어
- Content-Length: 표현 데이터의 길이
- 표현 헤더는 전송, 응답 둘다 사용
Content-Type
표현 데이터의 형식 설명
HTTP/1.1 200 OKContent-Type: text/html;charset=UTF-8Content-Length: 3423<html> <body>...</body></html>HTTP/1.1 200 OKContent-Type: application/jsonContent-Length: 16{"data" : "hello"}
- 미디어 타입, 문자 인코딩
- ex)
- text/html; charset=UTF-8
- application/json
- image/jpg
Content-Encoding
표현 데이터 인코딩
HTTP/1.1 200 OKContent-Type: text/html;charset=UTF-8Content-Encoding: gzipContent-Length: 521ikj123kljoiaudlkjaweiskskdjdhdjksksjdjdj
- 표현 데이터를 압축하는데 사용
- 데이터를 전달하는 곳에서 압축 후 인코딩 헤더 추가
- 데이터를 읽는 쪽에서 인코딩 헤더의 정보로 압축 해제
- ex)
Content-Language
표현 데이터의 자연 언어
HTTP/1.1 200 OKContent-Type: text/html;charset=UTF-8Content-Language: koContent-Length: 521<html> 안녕하세요</html>HTTP/1.1 200 OKContent-Type: text/html;charset=UTF-8Content-Language: enContent-Length: 521<html> Hello</html>
Content-Length
표현 데이터의 길이
HTTP/1.1 200 OKContent-Type: text/html;charset=UTF-8Content-Length: 5hello
- 바이트 단위
- Transfer-Encoding(전송 코딩)을 사용하면 Content-Length를 사용하면 안됨
참고 자료