Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
653 views
in Technique[技术] by (71.8m points)

nginx - How to generate 'last-modified' http header for a resource?

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.

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?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...