如何为资源生成“最后修改的" http标头? [英] How to generate 'last-modified' http header for a resource?

查看:81
本文介绍了如何为资源生成“最后修改的" http标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前阅读关于以下内容的 'last-modified'HTTP头.尽管我已经阅读了许多资源,但是我仍然困惑如何为特定资源生成它.

I currently read this about 'last-modified' HTTP header. Though I have read number of sources, I'm still confused how it is generated for a particular resource.

在db中更改资源时,它仅取决于时间戳吗?即当为数据库处理PUT请求时.在同一资源上?

Is it solely depends on the time stamp when the resource has changed in the db. i.e. as PUT requests are processed for the db. on the same resource?

或者有没有通用的或接近通用的逻辑来解决这个问题?

Or are there any generalized or nearly generalized logic to tackle the problem?

last-modified时间的产生,这仅是实际应用程序的责任吗?或还有其他方法吗?

And the generation of last-modified time, is it solely a responsibility of the actual application? or are there any other ways?

推荐答案

正如我在我对ETags ,提供标头的责任始终在于资源提供者.

As I mentioned in my answer about ETags, the responsibility to provide the header always lies with the resource provider.

ETags一样,Web服务器或框架可能有几种方法可以自动创建标头.到目前为止,最常见的情况是,提供静态文件的Web服务器可以使用文件的修改时间来设置Last-Modified标头.

And just as with ETags, there may be ways that the web server or framework can automate the creation of the header. By far the most common case is that web servers serving static files can use the files' modification time to set the Last-Modified header.

由于动态应用程序通常没有标准的信息来源,因此很难自动化.举一个我熟悉的示例,Django允许您

It's harder to automate with dynamic applications, since there's generally not a standard source of that information. To take an example I'm familiar with, Django allows you to specify a function that will be called to get the Last-Modified date. It's up to you to put the application-specific logic into that function, but the framework will populate the header and do the comparison to return Not Modified responses.

我的印象是,大多数动态应用程序都不会使用Last-Modified标头.如果必须提供自定义逻辑来找出缓存头,则最好只提供ETag,这通常是首选.另外,使用ETags,如果框架会为您哈希响应,则通常可以完全避免执行任何特定于应用程序的逻辑.

My impression is that most dynamic applications don't bother with the Last-Modified header. If you have to provide custom logic to figure out the caching headers, you might as well just provide the ETag, which is generally preferred. Also, with ETags you can often avoid doing any application-specific logic at all if the framework will hash the response for you.

这篇关于如何为资源生成“最后修改的" http标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆