메뉴 건너뛰기

infra

[PHP] transfer-encoding chunked

lispro062013.12.11 00:23조회 수 2083댓글 0

    • 글자 크기
chunked 형태로 response 하고 싶을 때, 아래와 같이 한다.

일반 response와 다른 점은 content-length가 header에 포함되지 않고, content에 표시되는 형태인데, 비교 자료가 있다.

header('Content-Encoding', 'chunked');
        header('Transfer-Encoding', 'chunked');
        header('Content-Type', 'text/html');
        header('Connection', 'keep-alive');

        ob_flush();
        flush();


 echo "data";




Normal Http

Chunked Http

해더 속성

HTTP/1.1 200 OK

Date: Sat, 03 Dec 2005 15:10:17 GMT

Server: Secured

Last-Modified: Sun, 18 Jan 2004 20:26:49 GMT

ETag: "64151-7dc-400aec09"

Accept-Ranges: bytes

Content-Length: 2012 <-- contents의 길이. 2012bytes

Connection: close

Content-Type: text/plain

HTTP/1.1 200 OK

Date: Sat, 03 Dec 2005 16:29:25 GMT

Server: Secured

Transfer-Encoding: chunked <-- chunked encoding

Content-Type: text/html

Http Header에 Content-Length 가 있다면, Content-Length에 적혀져 있는 길이만큼은 Body부분에서 수신한다.

보낼 양이 많을 경우 분할 하여 보낼 때 사용한다

예제

<html xmlns="http://www.w3.org/1999/xhtml">

<head profile="http://a9.com/-/spec/opensearch/1.1/">

<meta http-equiv="Content-Type" content="text/html;charset=euc-kr" />

<meta name="autocomplete" content="off" />

<title>Daum 에러페이지 | 페이지를 찾을 수 없음</title>

<body>

................

................

................

<body>

</html>

100 bytes 송신 시. (서버 설정치:40바이트)

 

1)

>40 (보낸 데이터의 크기_본래 16진수로 표시한다.)

>컨텐츠(40bytes)

>60 (남은 데이터의 크기)

 

2)

>40 (보낸 데이터의 크기)

>컨텐츠(40bytes)

>20 (남은 데이터의 크기)

 

3)

>20 (보낸 데이터의 크기)

>컨텐츠(20bytes)

>0 (남은 데이터의 크기)

특징

파일의 길이를 알아야 한다.

- 파일의 길이를 알 필요가 없다.

- 동적으로 생성하는 자원을 전송시 유용하다.

byte로 전송

chunk(덩어리로 전송)

 

끝은 CRLF, 길이가 0인 chunked를 보냄, 수신함으로 끝을 나타낸다.

lispro06 (비회원)
    • 글자 크기
[Andorid] droidbox 사용해 보기 (by lispro06) [protocol] TCP/IP 포트 할당에 대한 정보 (by 박영식)

댓글 달기

이전 1 ... 2 3 4 5 6 7 8 9 10 11다음
첨부 (0)
위로