<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SukmoonLee Blog &#187; etag</title>
	<atom:link href="http://blog.sukmoonlee.com/wordpress/archives/tag/etag/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.sukmoonlee.com/wordpress</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 20 Sep 2012 00:01:14 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Apache ETag</title>
		<link>http://blog.sukmoonlee.com/wordpress/archives/136</link>
		<comments>http://blog.sukmoonlee.com/wordpress/archives/136#comments</comments>
		<pubDate>Tue, 17 Apr 2012 12:40:35 +0000</pubDate>
		<dc:creator>Sukmoon Lee</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[etag]]></category>
		<category><![CDATA[http/1.1]]></category>

		<guid isPermaLink="false">http://blog.sukmoonlee.com/wordpress/?p=136</guid>
		<description><![CDATA[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값만을 사용하는 <a href='http://blog.sukmoonlee.com/wordpress/archives/136' class='excerpt-more'>[...]</a>]]></description>
				<content:encoded><![CDATA[<p>HTTP/1.1 에서 Cache와 관련된 헤더중에 If-Modified-Since와 ETag를 사용하는 방법이 있습니다.</p>
<p>ETag에 대한 설명은 아래에서 확인이 가능합니다.</p>
<blockquote><p><a href="http://en.wikipedia.org/wiki/HTTP_ETag">http://en.wikipedia.org/wiki/HTTP_ETag</a></p></blockquote>
<p>여기서 궁금한 것은 국내에서 많이 사용하고 있는 Apache 웹서버에서는 ETag 값을 어떻게 생성하는지가 궁금해서 소스를 다운받아서 확인을 해봤다.</p>
<p>아래 주석에서와 같이 <strong>inode-size-mtime</strong> 으로 구성이 하되, hex 값으로 변환을 해서 사용하도록 되어 있습니다. 물론 filetype이 0인 경우에는 mtime값만을 사용하는 것을 149라인에서 확인을 할수 있다.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;">    <span style="color: #0000dd;">113</span>     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>finfo.<span style="color: #202020;">filetype</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000dd;">114</span>         <span style="color: #808080; font-style: italic;">/*
    115          * ETag gets set to [W/]&quot;inode-size-mtime&quot;, modulo any
    116          * FileETag keywords.
    117          */</span>
    <span style="color: #0000dd;">118</span>         etag <span style="color: #339933;">=</span> apr_palloc<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>pool<span style="color: #339933;">,</span> weak_len <span style="color: #339933;">+</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>--<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
    <span style="color: #0000dd;">119</span>                           <span style="color: #0000dd;">3</span> <span style="color: #339933;">*</span> CHARS_PER_UINT64 <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">120</span>         next <span style="color: #339933;">=</span> etag<span style="color: #339933;">;</span>
    <span style="color: #0000dd;">121</span>         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>weak<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000dd;">122</span>             <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>weak<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000dd;">123</span>                 <span style="color: #339933;">*</span>next<span style="color: #339933;">++</span> <span style="color: #339933;">=</span> <span style="color: #339933;">*</span>weak<span style="color: #339933;">++;</span>
    <span style="color: #0000dd;">124</span>             <span style="color: #009900;">&#125;</span>
    <span style="color: #0000dd;">125</span>         <span style="color: #009900;">&#125;</span>
    <span style="color: #0000dd;">126</span>         <span style="color: #339933;">*</span>next<span style="color: #339933;">++</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">127</span>         bits_added <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">128</span>         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>etag_bits <span style="color: #339933;">&amp;</span> ETAG_INODE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000dd;">129</span>             next <span style="color: #339933;">=</span> etag_uint64_to_hex<span style="color: #009900;">&#40;</span>next<span style="color: #339933;">,</span> r<span style="color: #339933;">-&gt;</span>finfo.<span style="color: #202020;">inode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">130</span>             bits_added <span style="color: #339933;">|=</span> ETAG_INODE<span style="color: #339933;">;</span>
    <span style="color: #0000dd;">131</span>         <span style="color: #009900;">&#125;</span>
    <span style="color: #0000dd;">132</span>         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>etag_bits <span style="color: #339933;">&amp;</span> ETAG_SIZE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000dd;">133</span>             <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>bits_added <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000dd;">134</span>                 <span style="color: #339933;">*</span>next<span style="color: #339933;">++</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'-'</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">135</span>             <span style="color: #009900;">&#125;</span>
    <span style="color: #0000dd;">136</span>             next <span style="color: #339933;">=</span> etag_uint64_to_hex<span style="color: #009900;">&#40;</span>next<span style="color: #339933;">,</span> r<span style="color: #339933;">-&gt;</span>finfo.<span style="color: #202020;">size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">137</span>             bits_added <span style="color: #339933;">|=</span> ETAG_SIZE<span style="color: #339933;">;</span>
    <span style="color: #0000dd;">138</span>         <span style="color: #009900;">&#125;</span>
    <span style="color: #0000dd;">139</span>         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>etag_bits <span style="color: #339933;">&amp;</span> ETAG_MTIME<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000dd;">140</span>             <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>bits_added <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000dd;">141</span>                 <span style="color: #339933;">*</span>next<span style="color: #339933;">++</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'-'</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">142</span>             <span style="color: #009900;">&#125;</span>
    <span style="color: #0000dd;">143</span>             next <span style="color: #339933;">=</span> etag_uint64_to_hex<span style="color: #009900;">&#40;</span>next<span style="color: #339933;">,</span> r<span style="color: #339933;">-&gt;</span>mtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">144</span>         <span style="color: #009900;">&#125;</span>
    <span style="color: #0000dd;">145</span>         <span style="color: #339933;">*</span>next<span style="color: #339933;">++</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">146</span>         <span style="color: #339933;">*</span>next <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">147</span>     <span style="color: #009900;">&#125;</span>
    <span style="color: #0000dd;">148</span>     <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000dd;">149</span>         <span style="color: #808080; font-style: italic;">/*
    150          * Not a file document, so just use the mtime: [W/]&quot;mtime&quot;
    151          */</span>
    <span style="color: #0000dd;">152</span>         etag <span style="color: #339933;">=</span> apr_palloc<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">-&gt;</span>pool<span style="color: #339933;">,</span> weak_len <span style="color: #339933;">+</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
    <span style="color: #0000dd;">153</span>                           CHARS_PER_UINT64 <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">154</span>         next <span style="color: #339933;">=</span> etag<span style="color: #339933;">;</span>
    <span style="color: #0000dd;">155</span>         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>weak<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000dd;">156</span>             <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>weak<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000dd;">157</span>                 <span style="color: #339933;">*</span>next<span style="color: #339933;">++</span> <span style="color: #339933;">=</span> <span style="color: #339933;">*</span>weak<span style="color: #339933;">++;</span>
    <span style="color: #0000dd;">158</span>             <span style="color: #009900;">&#125;</span>
    <span style="color: #0000dd;">159</span>         <span style="color: #009900;">&#125;</span>
    <span style="color: #0000dd;">160</span>         <span style="color: #339933;">*</span>next<span style="color: #339933;">++</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">161</span>         next <span style="color: #339933;">=</span> etag_uint64_to_hex<span style="color: #009900;">&#40;</span>next<span style="color: #339933;">,</span> r<span style="color: #339933;">-&gt;</span>mtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">162</span>         <span style="color: #339933;">*</span>next<span style="color: #339933;">++</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">163</span>         <span style="color: #339933;">*</span>next <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span>
    <span style="color: #0000dd;">164</span>     <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>아래는 실제 Apache 서버에서 받은 HTTP 헤더에 들어 있는 ETag 값입니다.<br />
<a href="http://blog.sukmoonlee.com/wordpress/wp-content/uploads/2012/04/hfhfgffi.png"><img src="http://blog.sukmoonlee.com/wordpress/wp-content/uploads/2012/04/hfhfgffi.png" alt="" title="hfhfgffi" width="901" height="214" class="aligncenter size-full wp-image-139" /></a></p>
<p>위의 ETag 값을 검증해보기 위해서 마지막에 있는 0467ddaad 값을 10진수로 변환을 하고, 해당 값을 Unix Timestamp로 변환을 해보면 다음과 같이 확인이 가능합니다.<br />
<a href="http://blog.sukmoonlee.com/wordpress/wp-content/uploads/2012/04/gdbfidhe.png"><img src="http://blog.sukmoonlee.com/wordpress/wp-content/uploads/2012/04/gdbfidhe.png" alt="" title="gdbfidhe" width="397" height="110" class="aligncenter size-full wp-image-140" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sukmoonlee.com/wordpress/archives/136/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
