私のRubyonRailsアプリケーションは、次のコントローラーコードを使用してsitemap.xmlファイルを生成します。
class SitemapController < ApplicationController
layout nil
def index
headers['Content-Type'] = 'application/xml'
last_post = Post.last
if stale?(:etag => last_post, :last_modified => last_post.updated_at.utc)
respond_to do |format|
format.xml { @posts = Post.sitemap } # sitemap is a named scope
end
end
end
end
私の理解ではstale?
、コンテンツが変更されていない場合、メソッドはHTTP304未変更応答を保証する必要があります。ただし、curlまたはWebブラウザーを使用してこれをテストすると、常にHTTP200が取得されます。
$ curl --head localhost:3000 / sitemap.xml HTTP / 1.1 200 OK 接続:閉じる 日付:2009年4月13日月曜日15:50:00 GMT 最終変更日:2009年4月8日水曜日16:52:07 GMT Xランタイム:100 ETag:「5ff2ed60ddcdecf291e7191e1ad540f6」 キャッシュ制御:プライベート、max-age = 0、再検証する必要があります コンテンツタイプ:application / xml; charset = utf-8 コンテンツ-長さ:29318
stale?
メソッドを正しく使用していますか?これをローカルでテストすることも可能ですか?