Monday, April 22, 2013

1

quit the office

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="user-scalable=yes, initial-scale=1.0, minimum-scale=1.0, width=device-width" />
<link href="css/asm.css" rel="stylesheet" type="text/css">
<body>
<h1>
RFC2616 - Hypertext Transfer Protocol -- HTTP/1.1<br/>
Entities and Encodings
</h1>

<h3>- 실제 HTTP Response</h3>
<p>
<img src='./1.png'/>
message are crates, entity are cargo

<p><p><p><p><p>
<h3>- Entity Header Fields</h3>
 Entity Body를 설명하는 헤더, HTTP의 연결에 관한것과 무관
<br/><p/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Entity-header fields define metainformation about the entity-body or,<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if no body is present, about the resource identified by the request.<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Some of this metainformation is <b>OPTIONAL</b>; some might be REQUIRED by<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;portions of this specification.<br/>
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;entity-header&nbsp;&nbsp;&nbsp;= Allow &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; Section 14.7<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Content-Encoding&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; Section 14.11<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Content-Language&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; Section 14.12<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Content-Length&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; Section 14.13<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Content-Location&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; Section 14.14<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Content-MD5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; Section 14.15<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Content-Range&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; Section 14.16<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Content-Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; Section 14.17<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Expires&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; Section 14.21<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| Last-Modified&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; Section 14.29<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| extension-header<br/>
<br/>
       extension-header = message-header<br/>


<p/><p/><p/><p/><p/><p/>
<h3>- Entity Bodies<br/></h3>
 말그대로 실제 전달하고자 하는 데이타만 있고 모든 description은 header에 들어간다<br/>

CRLF 이후에 나온다. raw data 라고 할수있음. <br/>

OD(CR) OA(LF) 가 2번나오고 BODY가 나온다<br/>
<br/>
http://icon.daumcdn.net/w/c/12/11/10192021148946703.png<br/>
http://www.limsungguk.com<br/>


<h3>- Entity Header Fields</h3>
<h3>1. Content-Length <br/></h3>
 - 엔티티 바디의 사이즈<br/>
 - 압축을 했다면 압축한후의 사이즈<br/>
 - detect message truncation : 서버에서 전송중에 짤린다든지하는 성공적인 연결과 충돌을 구분할수 있다.<br/>
 <a href="https://code.google.com/p/chromium/codesearch#chromium/src/net/http/partial_data.cc&type=cs&l=340&rcl=1367374264">https://code.google.com/p/chromium/codesearch#chromium/src/net/http/partial_data.cc&type=cs&l=340&rcl=1367374264</a><br/>
 - cache proxy 에서도 쓰인다 : Content-length가 없다면 잘못된 전송구분이 힘드므로 cache하지않는다<br/>
 <a href="https://code.google.com/p/chromium/codesearch#chromium/src/net/http/http_cache_transaction.cc&type=cs&l=1622&rcl=1367374264">https://code.google.com/p/chromium/codesearch#chromium/src/net/http/http_cache_transaction.cc&type=cs&l=1622&rcl=1367374264</a><br/>
 - size demo - fiddler<br/>
 - chunked encoding을 쓰는경우에는 사용되지않을수 있다.<br/>

 <!--
 <p>
 Persistent Connections
 - follow the current response. where end, next begin,
 - "Transfer Encoding and Chunked Encoding"을 쓸수도있음 -> 뒤에서 볼거임
-->
<p/><p/><p/><p/>
<h3>2. Content-Encoding <br/></h3>
  - 보안, 압축 등이 적용되었을때 나타낸다.<br/>
  - Content-Length는 압축된 후의 값을 나타내야한다.<br/>
  - www.daum.net : Content-Encoding: gzip<br/>

<p/><p/><p/><p/>
<h3>Rules for Determining Entity Body Length (우선순위)</h3>
 1.<br/>- 특정 HTTP message는 Content-Length header를 무시한다.<br/>
 - HEAD Request(HEADER정보만수신)<br/>
 - 1XX(informational), 204(No Response), 304(Not modified)<br/>
<p>
 2. Transfer-Encoding header 일경우<br/>
<p>
 3. Content-Length header를 가질경우<br/>
<p>
 4. multipart/byterange의 media type을 갖고, entity length가 정의되지않은경우. 각 multipart message는
    own size를 정한다.<p>
 5. 위 Rule에 해당이 안될경우 entity는 connection이 끊길때 같이 끝난다고 판단한다. server 만이 연결을 끊을수있고,
  client는 끊을수없다. client가 보내는건 안되니까..(당연)<p>
 6. HTTP/1.0과 호환을 위해서 HTTP/1.1 Request중 Entity Body를 갖는놈은 valid Content-Length header field를 갖는다..<p>
 이메일파일전송같은..<p>

<h3>3. Content-MD5 <br/></h3>
 - Content-MD5 header는 MD5 algorithm을 body에 적용한다.<br/>
 - Transfer encoding을하고, MD5를 적용한다.<br/>
 - 실제 많이 쓰이지는 않음<br/>
<p>

<h3>4. Content-Type <br/></h3>
Media Type and Charset<br/>
 Content-Type header describes the MIME type of the entity body.<br/>
 - the MIME type is standarized name, registed with the Internet Assigned Numbers Authority (IANA)<br/>
 - Client app use MIME type to properly decipher and process the content. *<br/>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;media-type&nbsp;&nbsp;&nbsp;&nbsp;= type "/" subtype *( ";" parameter )<br/>
&nbsp;&nbsp;&nbsp;&nbsp;type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= token<br/>
&nbsp;&nbsp;&nbsp;&nbsp;subtype&nbsp;&nbsp;&nbsp;&nbsp;= token<p>
 - entity body가 encoding되었더라도 content-type header값은 encoding 하기전의 값을 갖는다.(html/html)<br/>
 - text일 경우 charset이 optional로 붙을수 있다.
  <p>Content-Type: text/html; charset=iso-8859-4<p>
 
<!--
 The "charset" parameter is used with some media types to define the
   character set (section 3.4) of the data. When no explicit charset
   parameter is provided by the sender, media subtypes of the "text"
   type are defined to have a default charset value of "ISO-8859-1" when
   received via HTTP. Data in character sets other than "ISO-8859-1" or
   its subsets MUST be labeled with an appropriate charset value. See
   section 3.4.1 for compatibility problems.
 - text라면 encoding
 - ISO 8859 그림
 -> mimetype browser 위치
Multipart Media Types
 - form을 통해서 전달할때.. small photo 등..
-->
----------------Encoding ------------------------<p>

<h3>4. Content Encoding <br/></h3>
 - amazon.com
 - yahoo.com

 Content-Encoding의 과정 <p>
 1) 웹서버가 원본메시지를 갖고 Content-Type와 Content-Length를 생성한다.<br/>
 2) content-encoidng 서버가 인코딩 메시지를 생성한다. Content-Type은 같지만(압축되었더라도), 다른 Content-Length를 갖게된다.<br/>
 3) content-encoding 서버가 Content-Encoding 헤더를 추가한다.<br/>

 그림 15-3<p/>

Content-Encoding Types<p>
 - gzip(gnu zip), compress(unix file compression), deflate(zlib), identity(no encoding) (IANA)<p>

Accept-Encoding Headers<p>
 - client 가 decoding 가능한 것을 알려줌(webbrowser)<br/>
 - 실젲 accept-encoding이 없으면 encoding 안해서 보내줌<p>

<p>
Transfer Encoding<br/>
 - What type of transformation has been applied to message body.

Safe Transport
 - Unknown size일경우, (streaming같은경우)
DEMO 실습

Transfer-Encoding: chunked 종류중에 하나
-> chunked size를 넣어 entity header에 full message size를 안넣어도 되도록한다.

RFC2616 ->
  If the TE field-value is empty or if no TE field is present, the only
   transfer-coding  is "chunked". A message with no transfer-coding is
   always acceptable.

Chunking and  Persistent Connections
When the connection betwen client and server is not persistent, no need to know sizeof body.
they expect to read the body until the server close connection.

gzip이나 deflate를 사용할경우 chunked로 감
-http://en.wikipedia.org/wiki/Chunked_transfer_encoding

실습 - ebay.com
OD OA - carriage return line feed

Chunked Encoding을 나타내는 방법 - last chunked는 무조건 0<CR><LR>

Time-Varying Instance.
the webpage instance can be change. range request & delta encoding을 통해 exact copy여부를 알수있다

Validator and Freshness
- 사이트를 cache 했지만 얼마나 유지할수있을까?? 금방바뀌는데
- expired를 갖고 있으면, 새로운 요청을 한다. 근데 사이트가 안바꼇을경우 또 받을필요가없다.
- Conditional request라고한다. 3가지 요소 Freshness, validators, conditional)

Freshness
서버는 expired 와 Cache-control을 통해 알려준다.
Expires : 날짜  - 언제끝날찌
Cache-Control : 몇초남았는지.

그림 똭

Conditional and Validator
- 기간이 다 지나서 새로운것을 받아오고자할때, 아직 서버에서는 안바꼈을수도있다.
</body>
</html>

No comments:

Post a Comment