Skip to content

Instantly share code, notes, and snippets.

@milabs
Created November 17, 2015 13:06
Show Gist options
  • Save milabs/c2c71b410bb725ea7a5a to your computer and use it in GitHub Desktop.
Save milabs/c2c71b410bb725ea7a5a to your computer and use it in GitHub Desktop.
Using URI::Fetch cached
use URI::Fetch;
use Cache::File;
use HTTP::Status qw(:constants);
$url = 'http://127.0.0.1:8080/media/snapshot.json.gz';
$cache = Cache::File->new(cache_root => '/tmp/cache');
$response = URI::Fetch->fetch($url, ForceResponse => 1, Cache => $cache);
if ($response->http_status == HTTP_OK) {
printf("200 OK\n");
} elsif ($response->http_status == HTTP_NOT_MODIFIED) {
printf("304 NOT MODIFIED\n");
} else {
printf("ERROR\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment