My Ruby on Rails ứng dụng sử dụng các mã điều khiển sau đây để tạo ra một file sitemap.xml:Cũ của Rails? phương pháp để sitemap luôn trả về HTTP 200
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
sự hiểu biết của tôi là phương pháp stale?
phải đảm bảo một HTTP 304 Not Modified phản ứng nếu nội dung không thay đổi. Tuy nhiên, bất cứ khi nào tôi thử nghiệm này sử dụng curl hoặc một trình duyệt web tôi luôn luôn nhận được một HTTP 200:
$ curl --head localhost:3000/sitemap.xml HTTP/1.1 200 OK Connection: close Date: Mon, 13 Apr 2009 15:50:00 GMT Last-Modified: Wed, 08 Apr 2009 16:52:07 GMT X-Runtime: 100 ETag: "5ff2ed60ddcdecf291e7191e1ad540f6" Cache-Control: private, max-age=0, must-revalidate Content-Type: application/xml; charset=utf-8 Content-Length: 29318
Tôi sử dụng phương pháp stale?
chính xác? Thậm chí có thể thử nghiệm địa phương này không?
Cảm ơn Adam, đúng vậy. –
Thật tuyệt vời, tôi hy vọng nó sẽ hữu ích cho bạn. Cảm ơn các cập nhật! –