Merge pull request #4870 from fkaelberer/enableTestServerCaching
Enable browser cache when running test server
This commit is contained in:
commit
001238fc4d
@ -655,6 +655,7 @@ function startServer() {
|
||||
server.host = host;
|
||||
server.port = options.port;
|
||||
server.root = '..';
|
||||
server.cacheExpirationTime = 3600;
|
||||
server.start();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user