West Wind Internet and Client Tools
How reliable is the HTTP Last-Modified header?
Gravatar is a globally recognized avatar based on your email address. How reliable is the HTTP Last-Modified header?
  Carl Chambers
  All
  Feb 9, 2025 @ 07:52pm

I have a process that I run at certain intervals whereby I download a number of PDF files and compare the contents of those files to previously downloaded versions of the same files.
I use wwHTTP to do the downloading.

I'm considering just downloading the headers for each file first (cHttpVerb="HEAD"), getting the Last-Modified header and then downloading the file only if the Last-Modified time is later than the time of the previous download. The logic being that, if the file has not been modified, there's no need to compare the contents.

Is the Last-Modified header reliable enough for that kind of usage?

Thanks,
Carl

Gravatar is a globally recognized avatar based on your email address. re: How reliable is the HTTP Last-Modified header?
  Rick Strahl
  Carl Chambers
  Feb 9, 2025 @ 08:30pm

Yes it should be, but ultimately it's up to the server to decide what it serves for the header. If you're serving static files from disk using default Web server file handling you can probably assume that the file dates are always up to date. Servers either run file watchers to notify them of file changes (if they cache) or explicitly look at the files when serving them.

If files are served dynamically, it depends on the implementation and it's up to the Web application to do the right thing.

Trust but verify, is a good call though - make sure you test!

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: How reliable is the HTTP Last-Modified header?
  Carl Chambers
  Rick Strahl
  Feb 10, 2025 @ 02:01pm

Thanks, Rick.

What made me question this was one source that had several PDFs in the same directory having identical Last-Modified values but I suppose if they were copied to that location fast enough they could all be copied within 1 second.
Another one I tested had more files and the timestamps varied within about a 4 second range.

So I'll follow your advice and test every source periodically to see if I'm getting consistent results. Given that I'm working with static files, I think this is going to work OK.

Thanks again for your help.

BTW, I just can't adequately express how impressed I am with these tools you've developed.
They enable me to do stuff I never thought I would.

Carl

Gravatar is a globally recognized avatar based on your email address. re: How reliable is the HTTP Last-Modified header?
  Rick Strahl
  Carl Chambers
  Feb 11, 2025 @ 09:25am

Thanks for the kind words...

Maturity of a product has its benefits - you find all the ways to make things as easy as possible 😄

+++ Rick ---

© 1996-2025