Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
633 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...