Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Updated Downloader to set the file's last modified time using the "La…
Browse files Browse the repository at this point in the history
…st-Modified" HTTP header. This fixes an issue where the "If-Modified-Since" HTTP header was ignored when issuing multiple requests in a short period of time. Using an exact date fixed the issue though the cause is unclear. (Perhaps some intermediary caching layer interpreted the header differently?). Closes #8
  • Loading branch information
f2bo committed May 20, 2015
1 parent e54e46b commit 0a78e52
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scripts/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ var downloadImage = function (inputUri, downloadDir, callback) {
// Else save
res.pipe(fs.createWriteStream(filePath))
.on('close', function () {
return callback(undefined, { 'path': filePath, 'statusCode': res.statusCode, 'statusMessage': res.statusMessage })
var lastAccessed = lastModified = new Date();
var lastModified = res.headers['last-modified'] ? new Date(res.headers['last-modified']) : lastAccessed;

// update the last modified time of the file to match the response header
fs.utimes(filePath, lastAccessed, lastModified, function (err) {
return callback(err, { 'path': filePath, 'statusCode': res.statusCode, 'statusMessage': res.statusMessage })
});
});
}).on('error', function(err) {
return callback(err);
Expand Down

0 comments on commit 0a78e52

Please sign in to comment.