This commit is contained in:
1 parent
a4b85162ab
commit
8ca69eecae
2 files changed
+10
-3
No files matched your search
@@ -207,7 +207,7 @@ function handleProxy(req, res, reqUrl) {
|
||||
clearTimeout(headersTimeout);
|
||||
|
||||
const proxyOrigin = getProxyOrigin(req);
|
||||
const rewriting = shouldRewriteBody(req, proxyRes);
|
||||
const rewriting = shouldRewriteBody(req, proxyRes, reqUrl.pathname);
|
||||
const responseHeaders = filterResponseHeaders(
|
||||
proxyRes.headers,
|
||||
rewriting
|
||||
|
||||
@@ -17,6 +17,7 @@ const HOP_BY_HOP = new Set([
|
||||
const STREAM_PATH = /^\/(live|movie|series|timeshift|hls|stream|vod)\//i;
|
||||
const STREAM_EXT =
|
||||
/\.(ts|m3u8|mp4|mkv|avi|mov|mpg|mpeg|flv|mp3|aac|m4a|m4v)$/i;
|
||||
const PLAYLIST_CONTENT_TYPE = /(mpegurl|m3u)/i;
|
||||
|
||||
class ReplaceStream extends Transform {
|
||||
constructor(replacements) {
|
||||
@@ -149,7 +150,7 @@ function isRewritableContentType(contentType) {
|
||||
);
|
||||
}
|
||||
|
||||
function shouldRewriteBody(req, upstreamResponse) {
|
||||
function shouldRewriteBody(req, upstreamResponse, pathname = '') {
|
||||
if (req.method === 'HEAD') return false;
|
||||
if (
|
||||
upstreamResponse.statusCode === 204 ||
|
||||
@@ -159,7 +160,13 @@ function shouldRewriteBody(req, upstreamResponse) {
|
||||
}
|
||||
const encoding = upstreamResponse.headers['content-encoding'];
|
||||
if (encoding && encoding.toLowerCase() !== 'identity') return false;
|
||||
return isRewritableContentType(upstreamResponse.headers['content-type']);
|
||||
|
||||
const contentType = upstreamResponse.headers['content-type'];
|
||||
const isPlaylist =
|
||||
PLAYLIST_CONTENT_TYPE.test(contentType || '') || /\.m3u8?$/i.test(pathname);
|
||||
if (isStreamPath(pathname) && !isPlaylist) return false;
|
||||
|
||||
return isRewritableContentType(contentType);
|
||||
}
|
||||
|
||||
function filterHopByHop(headers) {
|
||||
|
||||
Reference in new issue
Block a user