Merge pull request #1431 from lkiesow/x-accel

Implement X-Accel Redirect
This commit is contained in:
advplyr 2023-01-23 17:27:23 -06:00 committed by GitHub
commit 9ebe4b55dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 5 deletions

View file

@ -51,6 +51,11 @@ class CacheManager {
// Cache exists
if (await fs.pathExists(path)) {
if (global.XAccel) {
Logger.debug(`Use X-Accel to serve static file ${path}`)
return res.status(204).header({'X-Accel-Redirect': global.XAccel + path}).send()
}
const r = fs.createReadStream(path)
const ps = new stream.PassThrough()
stream.pipeline(r, ps, (err) => {
@ -72,6 +77,11 @@ class CacheManager {
// Set owner and permissions of cache image
await filePerms.setDefault(path)
if (global.XAccel) {
Logger.debug(`Use X-Accel to serve static file ${writtenFile}`)
return res.status(204).header({'X-Accel-Redirect': global.XAccel + writtenFile}).send()
}
var readStream = fs.createReadStream(writtenFile)
readStream.pipe(res)
}