Skip to content

Commit

Permalink
fixed youtube urlencode issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
netptop committed Mar 2, 2020
1 parent 98681c9 commit c365a9a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ let Proxy = ({httpprefix, serverName, port, cookieDomainRewrite, locationReplace
}
if (proxyRes.headers["content-type"].indexOf('text/') !== -1 ||
proxyRes.headers["content-type"].indexOf('javascript') !== -1 ||
proxyRes.headers["content-type"].indexOf('urlencoded') !== -1 ||
proxyRes.headers["content-type"].indexOf('json') !== -1) {
if (!gunzipped) {
res.status(404).send()
Expand All @@ -201,6 +202,11 @@ let Proxy = ({httpprefix, serverName, port, cookieDomainRewrite, locationReplace
handleRespond({req, res, body, gbFlag})
} else {
// console.log(`2========>${logGet()}`)
let key = "content-encoding"
if(key in proxyRes.headers) {
res.setHeader(key, proxyRes.headers[key]);
}
logSave(`2: res.headers:${JSON.stringify(res.getHeaders())}`)
res.end(body)
}

Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const regReplaceMap = {
'http://([-a-z0-9A-Z.]+)': `${httpprefix}://${serverName}:${port}/http/$1`,
'https%3a%2f%2f([-a-z0-9A-Z]+?)': `${httpprefix}%3a%2f%2f${serverName}%3a${port}%2fhttps%2f$1`,
'http%3a%2f%2f([-a-z0-9A-Z]+?)': `${httpprefix}%3a%2f%2f${serverName}%3a${port}%2fhttp%2f$1`,
'https%3A%2F%2F([-a-z0-9A-Z]+?)': `${httpprefix}%3A%2F%2F${serverName}%3A${port}%2Fhttps%2F$1`,
'http%3A%2F%2F([-a-z0-9A-Z]+?)': `${httpprefix}%3A%2F%2F${serverName}%3A${port}%2Fhttp%2F$1`,
' integrity=".+?"': '', // remove integrity
}

Expand Down Expand Up @@ -114,7 +116,8 @@ const siteSpecificReplace = {
},
'www.youtube.com': {
'b."get_video_info"': `"${httpprefix}://${serverName}:${port}/https/www.youtube.com/get_video_info"`,
'c<a.C.length': `c<a.C.length&&a.C[c].style`,
'c<a.C.length': `c<a.C.length&&a.C[c].style`, // fixed the exception.
'Ls.Ns.a.+?;': 'true};', // remove url check in base.js
// 'a.C.c..style.display=0==b': `a.C[c].style&&a.C[c].style.display=0==b`,
// '/manifest.json': `/https/www.youtube.com/manifest.json`,
// '("url":")/([-a-z0-9]+?)': `$1/https/www.youtube.com/$2`,
Expand Down
33 changes: 31 additions & 2 deletions test/siteproxylocal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ test('pingcong href="/" issue.', async () => {
url,
})
// console.log(`${JSON.stringify(response.headers)}`)
console.log(`${response.data}`)
// console.log(`${response.data}`)
expect(response.data.indexOf(`href="/"`)).toBe(-1)
}, 30000);

Expand All @@ -150,4 +150,33 @@ test('yorkbbs issue', async () => {
// console.log(`${JSON.stringify(response.headers)}`)
// console.log(`${response.data}`)
expect(response.data.indexOf(`ca//http`)).toBe(-1)
}, 30000);
}, 30000);

test('youtube response url encode issue', async () => {
const url = `${httpprefix}://${serverName}:${port}/https/www.youtube.com/get_video_info?html5=1&video_id=taVoseONjxc&cpn=DakN7Kk_Y_8rKsWf&eurl&el=embedded&hl=en_US&sts=18319&lact=30&c=WEB_EMBEDDED_PLAYER&cver=20200228&cplayer=UNIPLAYER&cbr=Chrome&cbrver=80.0.3987.87&cos=X11&autoplay=1&width=798&height=1048&ei=OgNcXrLJJMWItQeklqqgCw&iframe=1&embed_config=%7B%7D`
const response = await axios({
method: 'get',
headers: {
'Accept': `text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9`,
},
url,
})
// console.log(`${JSON.stringify(response.headers)}`)
// console.log(`${response.data}`)
expect(response.data.indexOf(`vss_host`)).not.toBe(-1)
}, 30000);


test('youtube url check issue', async () => {
const url = `${httpprefix}://${serverName}:${port}/https/www.youtube.com/yts/jsbin/player_ias-vflsFV4r3/en_US/base.js`
const response = await axios({
method: 'get',
headers: {
'Accept': `text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9`,
},
url,
})
// console.log(`${JSON.stringify(response.headers)}`)
console.log(`${response.data}`)
expect(response.data.indexOf(`Ls(Ns(a.`)).toBe(-1)
}, 30000);

0 comments on commit c365a9a

Please sign in to comment.