Merge pull request #4870 from fkaelberer/enableTestServerCaching

Enable browser cache when running test server
This commit is contained in:
Yury Delendik 2014-06-10 10:11:50 -05:00
commit 001238fc4d
2 changed files with 8 additions and 0 deletions

View File

@ -655,6 +655,7 @@ function startServer() {
server.host = host;
server.port = options.port;
server.root = '..';
server.cacheExpirationTime = 3600;
server.start();
}

View File

@ -47,6 +47,7 @@ function WebServer() {
this.port = 8000;
this.server = null;
this.verbose = false;
this.cacheExpirationTime = 0;
this.disableRangeRequests = false;
this.hooks = {
'GET': [],
@ -91,6 +92,7 @@ WebServer.prototype = {
}
var disableRangeRequests = this.disableRangeRequests;
var cacheExpirationTime = this.cacheExpirationTime;
var filePath;
fs.realpath(path.join(this.root, pathPart), checkFile);
@ -222,6 +224,11 @@ WebServer.prototype = {
}
res.setHeader('Content-Type', contentType);
res.setHeader('Content-Length', fileSize);
if (cacheExpirationTime > 0) {
var expireTime = new Date();
expireTime.setSeconds(expireTime.getSeconds() + cacheExpirationTime);
res.setHeader('Expires', expireTime.toUTCString());
}
res.writeHead(200);
stream.pipe(res);