Skip to content

Commit

Permalink
修复 CFW 返回编码错误的非 UFT-8 文件,更改版本号为 3.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaHOH committed Aug 30, 2021
1 parent 26126d5 commit 439d752
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions config/Config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ password =
explodeip = 1
iplist =
#是否解码被混淆的 Email 地址,影响 Content-Type 属于 'text/html' 或 'application/xhtml+xml' 的响应
#当文本编码不是 UTF-8 (即 Worker 解码错误),则不执行反混淆
decodeemail = 0
#连接超时设置
timeout = 10
Expand Down
2 changes: 1 addition & 1 deletion local/CFWFetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def cfw_fetch(method, host, url, headers, payload=b'', options=None):
worker_params = get_worker_params()
request_headers = {
'Host': worker_params.host,
'User-Agent': 'GotoX/ls/0.5',
'User-Agent': 'GotoX/ls/0.6',
'Accept-Encoding': ae,
'Content-Length': str(length),
'X-Fetch-Options': options_str,
Expand Down
2 changes: 1 addition & 1 deletion local/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.8.4'
__version__ = '3.8.5'
2 changes: 1 addition & 1 deletion pack_portable.ini
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ dnslib = >=0.9.12
PySocks = >=1.7.0

[extras-site-packages]
brotlipy = >=0.5.0
brotlicffi =
2 changes: 1 addition & 1 deletion remote/cloudflare_workers/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
0.5 测试版,支持基本的 HTTP 方法和 WebSocket。
0.6 测试版,支持基本的 HTTP 方法和 WebSocket。

此代理采用中间人方法实现代理,正常使用需要安装自签证书,运行 GotoX 并设置好代理,访问 http://gotox.go 安装证书。

Expand Down
11 changes: 9 additions & 2 deletions remote/cloudflare_workers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const about = `
/******************************************************************************
* GotoX remote server 0.5 in CloudFlare Workers
* GotoX remote server 0.6 in CloudFlare Workers
* https://github.com/SeaHOH/GotoX
* The MIT License - Copyright (c) 2020 SeaHOH
*
Expand Down Expand Up @@ -183,8 +183,15 @@ async function handleRequest(request) {
// cf.scrapeShield 参数无法关闭 Email Address Obfuscation,解码替换恢复
const ct = headers.has('Content-Type') ? headers.get('Content-Type') : ''
if (ct.includes('text/html') || ct.includes('application/xhtml+xml')) {
body = response.clone().body
// text() 强制使用 UTF-8 解码,编码错误时自动以备用字符替换
// U+FFFD �: REPLACEMENT CHARACTER
const html = await response.text()
body = cfEmail.decode(html)
if (!html.includes('\ufffd\ufffd\ufffd\ufffd')) {
const decoded = cfEmail.decode(html)
if (decoded !== html)
body = decoded
}
}
}
return new Response(body, {
Expand Down

0 comments on commit 439d752

Please sign in to comment.