Skip to content

Commit e1f7d2c

Browse files
committed
fixed gbk issue; removed the user-agent string for youtube
1 parent 587082a commit e1f7d2c

File tree

4 files changed

+53
-17
lines changed

4 files changed

+53
-17
lines changed

Proxy.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ let Proxy = ({ProxyMiddleware, blockedSites, urlModify, httpprefix, serverName,
367367
}
368368
let searchBody = body.slice(0, 1000)
369369
if (searchBody.indexOf('="text/html; charset=gb') !== -1 ||
370-
searchBody.indexOf(' charset="gb') !== -1 ||
370+
searchBody.search(/ontent=.*charset="gb/) !== -1 ||
371+
searchBody.search(/ONTENT=.*charset="gb/) !== -1 ||
371372
searchBody.indexOf('=\'text/html; charset=gb') !== -1) {
372373
logSave(`gb2312 found...`)
373374
body = iconv.decode(originBody, 'gbk')
@@ -551,7 +552,7 @@ let Proxy = ({ProxyMiddleware, blockedSites, urlModify, httpprefix, serverName,
551552
if (host.indexOf('youtube.com') !== -1) {
552553
// proxyReq.setHeader('User-Agent', `Opera/7.50 (Windows XP; U)`)
553554
// proxyReq.setHeader('User-Agent', `Opera/9.80 (Android 4.1.2; Linux; Opera Mobi/ADR-1305251841) Presto/2.11.355 Version/12.10`)
554-
proxyReq.setHeader('User-Agent', `Mozilla/5.0 (Linux; Android 6.0.1; Lenovo-A6020l36 Build/MMB29M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.93 Mobile Safari/537.36`)
555+
// proxyReq.setHeader('User-Agent', `Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0`)
555556
}
556557
logSave(`req host:${host}, req.url:${req.url}, proxyReq.query:${proxyReq.query} proxyReq.path:${proxyReq.path}, proxyReq.url:${proxyReq.url} proxyReq headers:${JSON.stringify(proxyReq.getHeaders())}`)
557558
if(host === '' || !host) {

build/worker.js

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"test": "jest",
99
"localtest": "localFlag=true jest siteproxylocal.test.js",
1010
"cftest": "jest cloudflare.test.js",
11+
"herokutest": "jest herokuapp.test.js",
1112
"start": "node --tls-min-v1.0 index.js",
1213
"localstartNow": "localFlag=true node --tls-min-v1.0 index.js",
1314
"localstart": "PORT=8011 localFlag=true node --tls-min-v1.0 index.js"
@@ -19,7 +20,7 @@
1920
"cookiejar": "^2.1.2",
2021
"express": "^4.17.1",
2122
"http-proxy-middleware": "^0.20.0",
22-
"iconv-lite": "^0.5.1",
23+
"iconv-lite": "^0.6.2",
2324
"pako": "^1.0.11",
2425
"query-string": "^6.11.1",
2526
"url-parse": "^1.4.7"

test/herokuapp.test.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @jest-environment node
3+
*/
4+
const axios = require('axios');
5+
6+
const httpprefix = 'https'
7+
const serverName = 'siteproxy.herokuapp.com'
8+
const port = '443'
9+
10+
test('post operation', async () => {
11+
const url = `${httpprefix}://${serverName}:${port}/https/api.twitter.com/1.1/branch/init.json`
12+
const response = await axios({
13+
method: 'post',
14+
validateStatus: null, // important for status 302/403
15+
headers: {
16+
authorization: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
17+
connection: 'keep-alive',
18+
cookie: 'personalization_id="v1_DkZdb/rVpgZVDtiT3qVAUA=="; guest_id=v1%3A160056087565376493; _ga=GA1.3.1320916387.1600483268; _gid=GA1.3.1182741545.1600483268; ORIGINALHOST=https/api.twitter.com',
19+
Host: 'siteproxy.herokuapp.com',
20+
Referer: 'https://siteproxy.herokuapp.com/explore',
21+
'Sec-Fetch-Dest': 'empty',
22+
'Sec-Fetch-Mode': 'cors',
23+
'Sec-Fetch-Site': 'same-origin',
24+
'x-csrf-token': 'ac1aa9d58c8798f0932410a1a564eb42',
25+
'x-twitter-active-user': 'yes',
26+
'x-twitter-client-language': 'en',
27+
},
28+
url,
29+
data:'',
30+
})
31+
console.log(`${JSON.stringify(response.headers)}`)
32+
console.log(`${JSON.stringify(response.data)}`)
33+
// expect(JSON.stringify(response.data).indexOf(`test data123`)).not.toBe(-1)
34+
}, 15000); // should be done within 3 seconds.

0 commit comments

Comments
 (0)