[질문] apache에서 content-length...
아파치에서 cgi를 이용해 동적으로 content가 만들어질 경우에는...
http header에 content-length가 들어오지를 않는군요.
이거 설정이 잘못된 것일까요?
제가 여러 자료를 보다 보니 아파치 자체의 문제라는 글도 보이던데...
Chunked TransfersNormally, when sending back a response the sever has to know everything about the response it is about to send before it sends it. For instance, servers should set the Content-Length header on each response to the length of the response itself. This can be difficult for the server to do if the content is dynamically created (e.g. if it is the output of a CGI script). So in practice servers (including Apache) often do not send a Content-Length with dynamic documents. This has not been a problem with HTTP/1.0, but for persistent connections to work in HTTP/1.1, the Content-Length must be known in advance.
The server could find out the length of the output of a CGI script by reading it into memory until the script has finished, then setting the Content-Length and returning the stored content. This might be acceptable for small content, but could be a problem if the CGI produces a lot of output. One possible way around this is to use the new chunked encoding method. This lets the server send output a bit at a time. Each bit (or chunk) is small enough for its content-length to be known before it is sent. Using chunked encoding will let servers send out dynamic content that is either large or produced slowly without having to disable persistent connections.
In addition, after a chunked-encoded document has been completely sent, additional response headers can be transmitted. This could allow dynamically produced headers to be associated with the document, even if they are not available until after the script (or whatever produced the document) has finished.
위에서 말한 chunked transfer에 대한 설명 or 설정법 좀 부탁드립니다.
==============================================
사실... 웹서버로 telnet을 통해 질의를 해보면...
GET / HTTP/1.1
HTTP/1.1 400 Bad Request
Date: Tue, 08 Jun 2004 04:41:55 GMT
Server: Apache/1.3.24 (Unix) mod_jk/1.2.1-beta-1 PHP/4.2.2 mod_fastcgi/2.2.12
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1
170
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
위에 처럼 "Transfer-Encoding: chunked" 라고 오긴하는데...
Content-Length는 없네요.
==============================================
사실 이 chunked transfer가 지금 제 상황에선 답이 되진 않지만...(한번에 content-length 받아서 그 만큼의 buffer 할당을 하고 recv 해야하는 상황이거든요)...
다른 방법이나 조언도 있으시다면 부탁드립니다.
좋은 하루 되세요
chunked 는 전체 도큐먼트의 크기를 알 수 없을때(동적인 문서) 자
chunked 는 전체 도큐먼트의 크기를 알 수 없을때(동적인 문서) 자주 사용됩니다. CGI, PHP 등이 이런 경우에 속하는데요..
보시면 170은 16진수 입니다. 10진수로 변환시켜 보시면 다음 chunk까지의 데이터 크기가 됩니다.
마지막에 0 이라는 chunk 가 올 때까지 도큐멘트를 받으면 됩니다.
이런식으로요..
HTTP/1.1 RFC에 더 자세한 스펙이 있습니다~
아! 감사합니다.
좋은 글 덕분에 HTTP 스펙 다시 봤습니다.
고맙습니다 ^^
댓글 달기