我通过 python Flask 提供动态创建的 recent.rss
服务,自然地,它总是通过 200 OK
发送。我打算通过设置标头 Expires
到未来一周并检查浏览器是否发送 If-Modified-Since
来解决此问题。
如果是这样(比较日期后)我只会返回任何内容,304
而不是返回响应
,但根据Firebug和request.environ
我的浏览器永远不会发送该资源的 If-Modified-Since
。
我知道我可以将数据保存到文件中并使用网络服务器将其作为真正的静态文件提供服务,但我最终可能真的需要通过 WSGI 提供静态文件,即使不需要,我也想知道为什么这不会'不工作。
感谢您的任何帮助。
I'm serving a dynamically created recent.rss
via python flask and naturally that way it is always sent via 200 OK
. I was going to fix this by setting the header Expires
a week into the future and checking if the browser sent If-Modified-Since
.
If so (after comparing dates) I would just do return nothing, 304
instead of return response
, but according to Firebug and request.environ
my browser just never sends If-Modified-Since
for that ressource.
I know I could just save the data to a file and serve it as a real static file using a webserver, but I might end up really needing to serve static files via WSGI and even if not I'd like to know why this doesn't work.
Thanks for any help.
发布评论
评论(1)
RFC 2616 HTTP/1.1 在 14.25 If-Modified-Since:
这表明当您期望/希望客户端发送
If-Modified-Since
时,您应该发送Last-Modified
标头。RFC 2616 HTTP/1.1 has this note in 14.25 If-Modified-Since:
This indicates that you should send a
Last-Modified
header when you expect/want the client to sendIf-Modified-Since
.