Skip to content

Instantly share code, notes, and snippets.

@coderanger
Created April 20, 2011 23:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save coderanger/08e93d2f03bd4e875264 to your computer and use it in GitHub Desktop.
Save coderanger/08e93d2f03bd4e875264 to your computer and use it in GitHub Desktop.
Example of using http_request to only download files if the mtime changes.
remote = "http://couchdb.apache.org/img/sketch.png"
local = "/tmp/couch.png"
remote_file local do
source remote
action :nothing
end
http_request "HEAD #{remote}" do
message ""
url remote
action :head
if File.exists?(local)
headers "If-Modified-Since" => File.mtime(local).httpdate
end
notifies :create, resources(:remote_file => local), :immediately
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment