Page 1 of 1

HTTP client detect if resourse has been updated

Posted: Tue Apr 26, 2022 6:28 am
by rtborg
Is there a way to detect if a HTTP resource has been changed without downloading it?

The case is: I have a file on the filesystem, which needs to be synced with a file on a HTTP server; if the file on the ESP is updated, it should be uploaded to the HTTP server; and if the file on the server is changed, the ESP should download and update its local copy.

What is the best way to check if the resource has been changed on the server, if there is such a way, without downloading it? I'll run a periodic task which will check for updates, and if I need to download the file each time that will add to a lot of overhead and needless SD card wearing.

Re: HTTP client detect if resourse has been updated

Posted: Wed Apr 27, 2022 1:14 am
by ESP_Sprite
Purely looking at the HTTP protocol itself, you could either use a HEAD (instead of a GET) request to get only the headers of the page and then look at the 'last-modified' header, or you could use an If-Modified-Since field to tell the webserver to only return a result if the file has changed after a certain date.