h1.1. HTTP 상태코드
h3.1.1 응답 메시지 & 상태라인
bq.After receiving and interpreting a request message, a server responds with an HTTP response message.
요청 메시지를 받고 해석한 뒤에, 서버는 HTTP 응답 메시지를 보낸다.
Example:
| HTTP/1.1 304 Not Modified Date: Fri, 07 Sep 2012 14:51:43 GMT Server: Apache/2.2.22 (Win32) mod_jk/1.2.37 Connection: Keep-Alive Keep-Alive: timeout=5, max=94 ETag: "d00000001f216-1e7-4c908f1fc4d6e" |
The first line of a Response message is the Status-Line, consisting of the protocol version followed by a numeric status code and its associated textual phrase, with each element separated by SP characters. No CR or LF is allowed except in the final CRLF sequence.
Status-Line = HTTP-Version SP{color:red} Status-Code{color} SP Reason-Phrase CRLF
h3.1.2 상태코드란
상태코드는 세자리 숫자 결과코드로 요청에 대해 이해하고 요청에 대해 이해하고 만족하기 위해 사용한다.
bq.The Status-Code element is a 3-digit integer result code of the attempt to understand and satisfy the request.
h3.1.3 상태코드의 분류
상태코드의 첫번째 자리는 요청결과 분류를 정의한다. 나머지 두자리는 어떤 분류 규칙도 없다.
bq.The first digit of the Status-Code defines the class of response. The last two digits do not have any categorization role.
h3.1.3 3xx 상태코드
개별적인 상태코드는 HTTP/1.1 에 정의되어 있지만 프로토콜에 영향을 주는 않는 논리적인 위치에서는 변경가능하다.
bq.The individual values of the numeric status codes defined for HTTP/1.1, and an example set of corresponding Reason-Phrase's, are presented below. The reason phrases listed here are only recommendations – they MAY be replaced by local equivalents without affecting the protocol.
| 3xx: Redirection - 요청이 완수되기 위해서 추가적인 동작이 이뤄져야 한다. |
h1.2. 304 Not Modified
h3.2.1 Conditional GET Request
HTTP Get 의 특별한 타입으로 요청 메시지에 다음 필드가 있다면 HTTP Conditional Get 으로 변경한다.
※ 대부분의 브라우저는 HTTP conditional request를 사용하여 자동 캐시 기능을 지원한다.
h3.2.2 304 응답
클라이언트가 조건부 GET 요청을 실행하고 접근이 허용되었지만 문서가 수정되지 않았다면, 서버는 304 상태코드로 응답한다. 304 응답은 메시지-바디 를 절대 포함하면 안된다. 그래서 이것은 항상 헤더 필드후에 처음 공백라인으로 종료된다.
bq.If the client has performed a conditional GET request and access is allowed, but the document has not been modified, the server SHOULD respond with this status code. The 304 response MUST NOT contain a message-body, and thus is always terminated by the first empty line after the header fields.
만약 304 응답이 현재 캐시되지 않은 엔티티를 지시하면, 캐쉬는 반드시 이 응답을 무시하고 조건없는 요청을 반복해야 한다.
bq.If a 304 response indicates an entity not currently cached, then the cache MUST disregard the response and repeat the request without the conditional.
h1.3. 304 응답 테스트
h3.3.1 요청 테스트
h3.3.2 304 응답을 받았지만 캐시된 파일이 없는 경우
long lastModifiedDate = ogetFileLastModifiedDate(fileName);
long clientDate = request.getDateHeader("If-Modified-Since");
if (clientDate != -1 && clientDate >= lastModifiedDate) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}else{
response.setDateHeader("Last-Modified", lastModifiedDate);
}
h1.참고
http://ruturajv.wordpress.com/2005/12/27/conditional-get-request/
http://www.codeguru.com/csharp/.net/net_general/internet/article.php/c16073/Tip-HTTP-Conditional-Get.htm