HTTP client detect if resourse has been updated

rtborg
Posts: 67
Joined: Wed Oct 23, 2019 6:15 am

HTTP client detect if resourse has been updated

Postby rtborg » Tue Apr 26, 2022 6:28 am

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.

ESP_Sprite
Posts: 9746
Joined: Thu Nov 26, 2015 4:08 am

Re: HTTP client detect if resourse has been updated

Postby ESP_Sprite » Wed Apr 27, 2022 1:14 am

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.

Who is online

Users browsing this forum: No registered users and 88 guests