1111
This commit is contained in:
parent
bf6cebe31a
commit
930236657a
15
index.js
15
index.js
@ -200,8 +200,8 @@ const fetchAndServe = (data, tempCacheContentFile, cacheContentFile, res) => {
|
|||||||
|
|
||||||
let isVideo = data.path && typeof data.path === 'string' && data.path.includes('.mp4');
|
let isVideo = data.path && typeof data.path === 'string' && data.path.includes('.mp4');
|
||||||
data.headers['content-length'] = realRes.headers['content-length'];
|
data.headers['content-length'] = realRes.headers['content-length'];
|
||||||
res.writeHead(realRes.statusCode, {
|
|
||||||
...data.headers,
|
const defaultHeaders = {
|
||||||
'Cloud-Type': data.cloudtype,
|
'Cloud-Type': data.cloudtype,
|
||||||
'Cloud-Expiration': data.expiration,
|
'Cloud-Expiration': data.expiration,
|
||||||
'Content-Type': isVideo ? 'video/mp4' : 'application/octet-stream',
|
'Content-Type': isVideo ? 'video/mp4' : 'application/octet-stream',
|
||||||
@ -212,7 +212,8 @@ const fetchAndServe = (data, tempCacheContentFile, cacheContentFile, res) => {
|
|||||||
'Connection': 'keep-alive',
|
'Connection': 'keep-alive',
|
||||||
'Date': new Date().toUTCString(),
|
'Date': new Date().toUTCString(),
|
||||||
'Last-Modified': new Date().toUTCString(),
|
'Last-Modified': new Date().toUTCString(),
|
||||||
});
|
};
|
||||||
|
res.writeHead(realRes.statusCode, Object.assign({}, defaultHeaders, data.headers));
|
||||||
|
|
||||||
realRes.pipe(cacheStream);
|
realRes.pipe(cacheStream);
|
||||||
realRes.pipe(res);
|
realRes.pipe(res);
|
||||||
@ -250,8 +251,8 @@ const serveFromCache = (cacheMetaFile, cacheContentFile, res) => {
|
|||||||
cacheData.headers['content-length'] = fs.statSync(cacheContentFile).size;
|
cacheData.headers['content-length'] = fs.statSync(cacheContentFile).size;
|
||||||
|
|
||||||
readStream.on('open', () => {
|
readStream.on('open', () => {
|
||||||
res.writeHead(200, {
|
|
||||||
...cacheData.headers,
|
const defaultHeaders = {
|
||||||
'Cloud-Type': cacheData.cloudtype,
|
'Cloud-Type': cacheData.cloudtype,
|
||||||
'Cloud-Expiration': cacheData.expiration,
|
'Cloud-Expiration': cacheData.expiration,
|
||||||
'Content-Type': isVideo ? 'video/mp4' : 'application/octet-stream',
|
'Content-Type': isVideo ? 'video/mp4' : 'application/octet-stream',
|
||||||
@ -262,7 +263,9 @@ const serveFromCache = (cacheMetaFile, cacheContentFile, res) => {
|
|||||||
'Connection': 'keep-alive',
|
'Connection': 'keep-alive',
|
||||||
'Date': new Date().toUTCString(),
|
'Date': new Date().toUTCString(),
|
||||||
'Last-Modified': new Date().toUTCString(),
|
'Last-Modified': new Date().toUTCString(),
|
||||||
});
|
}
|
||||||
|
|
||||||
|
res.writeHead(200, Object.assign({}, defaultHeaders, cacheData.headers));
|
||||||
readStream.pipe(res);
|
readStream.pipe(res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user