Apr 172012
 

HTTP/1.1 에서 Cache와 관련된 헤더중에 If-Modified-Since와 ETag를 사용하는 방법이 있습니다.

ETag에 대한 설명은 아래에서 확인이 가능합니다.

http://en.wikipedia.org/wiki/HTTP_ETag

여기서 궁금한 것은 국내에서 많이 사용하고 있는 Apache 웹서버에서는 ETag 값을 어떻게 생성하는지가 궁금해서 소스를 다운받아서 확인을 해봤다.

아래 주석에서와 같이 inode-size-mtime 으로 구성이 하되, hex 값으로 변환을 해서 사용하도록 되어 있습니다. 물론 filetype이 0인 경우에는 mtime값만을 사용하는 것을 149라인에서 확인을 할수 있다.

    113     if (r->finfo.filetype != 0) {
    114         /*
    115          * ETag gets set to [W/]"inode-size-mtime", modulo any
    116          * FileETag keywords.
    117          */
    118         etag = apr_palloc(r->pool, weak_len + sizeof("\"--\"") +
    119                           3 * CHARS_PER_UINT64 + 1);
    120         next = etag;
    121         if (weak) {
    122             while (*weak) {
    123                 *next++ = *weak++;
    124             }
    125         }
    126         *next++ = '"';
    127         bits_added = 0;
    128         if (etag_bits & ETAG_INODE) {
    129             next = etag_uint64_to_hex(next, r->finfo.inode);
    130             bits_added |= ETAG_INODE;
    131         }
    132         if (etag_bits & ETAG_SIZE) {
    133             if (bits_added != 0) {
    134                 *next++ = '-';
    135             }
    136             next = etag_uint64_to_hex(next, r->finfo.size);
    137             bits_added |= ETAG_SIZE;
    138         }
    139         if (etag_bits & ETAG_MTIME) {
    140             if (bits_added != 0) {
    141                 *next++ = '-';
    142             }
    143             next = etag_uint64_to_hex(next, r->mtime);
    144         }
    145         *next++ = '"';
    146         *next = '\0';
    147     }
    148     else {
    149         /*
    150          * Not a file document, so just use the mtime: [W/]"mtime"
    151          */
    152         etag = apr_palloc(r->pool, weak_len + sizeof("\"\"") +
    153                           CHARS_PER_UINT64 + 1);
    154         next = etag;
    155         if (weak) {
    156             while (*weak) {
    157                 *next++ = *weak++;
    158             }
    159         }
    160         *next++ = '"';
    161         next = etag_uint64_to_hex(next, r->mtime);
    162         *next++ = '"';
    163         *next = '\0';
    164     }

아래는 실제 Apache 서버에서 받은 HTTP 헤더에 들어 있는 ETag 값입니다.

위의 ETag 값을 검증해보기 위해서 마지막에 있는 0467ddaad 값을 10진수로 변환을 하고, 해당 값을 Unix Timestamp로 변환을 해보면 다음과 같이 확인이 가능합니다.

Print Friendly

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/smlee/blog/wordpress/wp-content/plugins/seo-facebook-comments/seofacebook.php on line 488

Warning: Invalid argument supplied for foreach() in /home/smlee/blog/wordpress/wp-content/plugins/seo-facebook-comments/seofacebook.php on line 490

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Plugin from the creators of Brindes :: More at Plulz Wordpress Plugins