36
15. Entities & Encodings 아아아

HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Embed Size (px)

Citation preview

Page 1: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

15. Entities & Encodings

아꿈사

Page 2: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

HTTP ships billions of media objects of all

kinds every day

Page 3: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

HTTP ensure these• Can be identified correctly(Content-type, Content-

Language headers)

• Can be unpacked properly(Content-length, Content-Encoding headers)

• Is fresh(entity validator, cache-expiration)

• Meets the user’s needs(Accept headers)

• Moves quickly(range requests, delta encoding/compression)

• Arrives complete(transfer encoding header, Content-MD5)

Page 4: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

HTTP Messages,Entities

• Messages -> Crates( 컨테이너 )

• Entities -> Cargo( 화물 )

Page 5: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Entity headers(1)• 엔터티 본문에 해당하는 해더• 본문 크기와 콘텐츠 , 혹은 리소스 그 자체를 서술

Page 6: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Entity headers(2)• Content-Type• Content-Length• Content-Language• Content-Location• Content-Range• Content-MD5• Last-Modified• Expires• Allow• Etag• Cache-Control

Page 7: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Entity Bodies• 가공되지 않은 (raw) 데이터만을 담고 있다 .

• Content-Type 엔터티 헤더가 데이터 타입을 설명(image/jpeg, text/javascript)

• Content-Encoding 엔터티 헤더가 압축 혹인 인코딩 여부를 설명 (gzip)

Page 8: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Content-Length(1)

• 엔터티 본문의 크기를 바이트 단위로 표현( 압축이 되었다면 , 압축 후의 크기 )

• 엔터티 본문이 있다면 필수적으로 있어야할 헤더( 메시지가 chunked encoding 일 때는 필수 X)

Page 9: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Content-Length(2)

• 메시지 잘림 (truncation) 을 검출하기 위해 사용( Older versions of HTTP used connection close to delimit the end of a message)

• Content-Length 헤더가 없으면 HTTP 본문을 캐싱하지 않는다 .

Page 10: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Content-Length(3)

• 지속 커넥션에서는 Content-Length 헤더 필수The Content-Length header lets the client know where one message ends and the next begins.

• chunked encoding 인 데이터는 예외

Page 11: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

엔터티 본문 길이 규칙1. 본문 (body) 가 허용되지 않는 특정 타입의 경우 ,

Content-Length 헤더 무시 (HEAD)

2. Transfer-Encoding 헤더가 있다면 , zero-byte chunk로 끝나야한다 .

3. Content-Length 헤더가 있다면 , 본문의 길이를 나타냄(Transfer-Encoding 헤더가 있다면 , Content-Length무시 )

4. multipart/byteranges 미디어 타입이라면 자기가 알아서 계산5. 엔터티는 커넥션이 닫힐 때 , 끝난다 .

Page 12: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

엔터티 요약 (digests)• HTTP 메시지가 변형되는 것을 방지 , 체크섬 생성• Content-MD5 (MD5 적용 )

• 중단간 프락시와 캐시는 해당 헤더를 변경하지 않음• 중복 저장 방지를 위한 해시 테이블의 키로 사용• Want-Digest

Page 13: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Media Type and Charset

• 엔티티 본문의 MIME 타입을 기술• 콘텐츠를 적절히 해독하고 처리하기 위해 사용• 원본 엔터티 본문의 미디어 타입을 명시• 형식 : primary media type / subtype

Page 14: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Media Type and Charset

Page 15: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

멀티파트 폼 제출 (1)

• 여러 개의 메시지를 포함해서 ( 한개의 폼으로 ) 전송• HTTP 폼을 채워서 제출하면 , 멀티파트로 구성이 되어 제출

Page 16: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)
Page 17: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Content-Encoding Process(1)

1. 웹서버가 Content-type, Content-Length 헤더로 원본 응답 메시지 생성2. 콘텐츠 인코딩 서버가 인코딩 (Content-Encoding추가 )

Content-Length 가 변경되면 수정3. 수신 측 프로그램은 인코딩된 메세지를 받아 디코딩

Page 18: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Content-Encoding Process(2)

Page 19: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Content-Encoding Types

• gzip, compress, deflate 인코딩은 무손실 압축• gzip 이 가장 일반적인 알고리즘

Page 20: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Accept-Encoding Headers

• 클라이언트가 지원하지 않는 인코딩을 막기위해• 클라이언트가 지원하는 인코딩 목록을 전달

Page 21: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Transfer / Chunked Encoding(1)

• 텍스트 파일은 gzip 압축 후 , Content-Encoding

• JPEG 파일은 압축률이 낮다 -> 네트워크를 통해 전송되는방법을 바꾼다 .

Page 22: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Transfer / Chunked Encoding(2)

Page 23: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

몇 가지 문제• unknown size

• security

Page 24: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Transfer-Encoding Headers

• Trnasfer-Encoding

• 어떠한 인코딩이 적용되어있는지 수신자에게 알림• TE

• 서버에게 어떤 전송인코딩을 사용할 수 있는지 알림

Page 25: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Chunked Encoding(1)

• 메시지를 일정 크기의 여러 청크로 쪼갠다 .

• 서버는 각 청크를 순차적으로 전송• 동적으로 본문을 생성 , 빠르게 전송

Page 26: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Chunked Encoding(2)

Page 27: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Content and Transfer Encodings

Page 28: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Transfer-Encoding 규칙• 전송 인코딩의 집합은 반드시 ‘ chunked’ 를 포함해야한다 .

• 메시지 본문에 적용된 마지막 전송 인코딩이 존재해야한다 .

• 청크 전송 인코딩은 반드시 메시지 본문에 한 번 이상 적용되어야한다 .

Page 29: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Freshness• Expires Header

• 얼마나 오랫동안 컨텐츠를 캐시해야하는지 명시• 하지만 클라이언트와 시계를 동기화 하기 어려움• Expires: Sun Mar 18 23:59:59 GMT 2001

• Cache-Control

• 서버를 떠난 후로부터의 총 시간을 초단위로 설정• cache-control:private,max-age=31535990

Page 30: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Validator(1)

• 캐시된 사본이 신선하지 않다면 , 서버에서 가져옴• 서버와 캐시된 파일이 같은지 검증• 네트워크 대여폭 낭비를 줄이고 , 캐시와 서버에 불필요한 부하를 줄이기 위해서

Page 31: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Validator(2)

• ETag(Entity Tag)

• An ETag is an opaque identifier assigned by a web server to a specific version of a resource found at a URL. If the resource representation at that URL ever changes, a new and different ETag is assigned.

Page 32: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Validator(3)

Page 33: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Range Requests(1)

• 클라이언트가 문서의 일부분이나 특정 범위만을 요청• 모든 서버가 Range request 를 받을 수 있는건 아님• 파일공유 클라이언트 , 멀티미디어 다운로드

Page 34: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Range Requests(2)

나는 Range request 처리가능

Page 35: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Delta Encoding(1)

• 페이지 변경 시 , 클라이언트에 캐싱된 부분과 서버 파일에 변경된 부분만 전송하는 방법 (RFC3329)

Page 36: HTTP 완벽가이드 - ch15. 엔터티, 인코딩 (Entities and Encoding)

Delta Encoding(2)