Skip to content

Commit 48aa018

Browse files
修复qx echo-response 转loon mock失败的问题
修复jq输出到shadowrocket时会丢失的问题 修复surge body rewrite转至loon时type错误的显示为jq的问题
1 parent 1401d64 commit 48aa018

File tree

2 files changed

+54
-24
lines changed

2 files changed

+54
-24
lines changed

Rewrite-Parser.beta.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ if (binaryInfo != null && binaryInfo.length > 0) {
560560

561561
if (/\s((request|response)-body-json-jq)\s|\surl\sjsonjq-(response|request)-body/.test(_x)) {
562562
let [_, regex, type, value] = _x.match(/^(.*?)\s+?(?:url\s+?jsonjq-)?(request|response)-body(?:-json-jq)?\s+?(.*?)\s*$/)
563-
if (jqEnabled && (isSurgeiOS || isStashiOS)) {
563+
if (jqEnabled && (isSurgeiOS || isStashiOS || isShadowrocket)) {
564564
const jqPath = value.match(/jq-path="(.+?)"/)?.[1]
565565
if (jqPath) {
566566
if (/^https?:\/\//.test(jqPath)) {
@@ -1302,11 +1302,25 @@ if (binaryInfo != null && binaryInfo.length > 0) {
13021302
const { type, regex, value } = rwbodyBox[i]
13031303
if (isSurgeiOS || isShadowrocket){
13041304
BodyRewrite.push(`${type} ${regex} ${value}`)
1305-
}else if (isLooniOS){
1306-
let type2 = /request/.test(type) ? 'request-body-json-jq' : 'response-body-json-jq';
1305+
} else if (isLooniOS) {
1306+
let type2
1307+
switch (type) {
1308+
case 'http-request':
1309+
type2 = 'request-body-replace-regex'
1310+
break
1311+
case 'http-response':
1312+
type2 = 'response-body-replace-regex'
1313+
break
1314+
case 'http-request-jq':
1315+
type2 = 'request-body-json-jq'
1316+
break
1317+
case 'http-response-jq':
1318+
type2 = 'response-body-json-jq'
1319+
break
1320+
}
13071321
URLRewrite.push(`${regex} ${type2} ${value}`)
13081322
}
1309-
1323+
13101324
}
13111325

13121326
//headerRewrite输出
@@ -1400,13 +1414,13 @@ if (binaryInfo != null && binaryInfo.length > 0) {
14001414
case 'loon-plugin':
14011415
URLRewrite.push(
14021416
mark +
1403-
noteK +
1404-
mockptn +
1405-
' mock-response-body' +
1406-
mocktype +
1407-
(mockBox[i].datapath ? ` data-path=${mockBox[i].datapath}` : ` data="${mockBox[i].data}"`) +
1408-
mockstatus +
1409-
(mockBox[i].mockbase64 ? ' mock-data-is-base64=true' : '')
1417+
noteK +
1418+
mockptn +
1419+
' mock-response-body' +
1420+
mocktype +
1421+
(mockBox[i].datapath ? ` data-path=${mockBox[i].datapath}` : mockBox[i].data ? ` data="${mockBox[i].data}"` : mockBox[i].mockurl ? ` data-path=${mockBox[i].mockurl}` : "") +
1422+
mockstatus +
1423+
(mockBox[i].mockbase64 ? ' mock-data-is-base64=true' : '')
14101424
)
14111425
break
14121426
} //switch
@@ -2143,6 +2157,7 @@ function getMockInfo(x, mark, y) {
21432157
mockurl = x.split(/\s+echo-response\s+/)[2]
21442158
mocktype = 'file'
21452159
mockheader = '&contentType=' + encodeURIComponent(x.split(/\s+echo-response\s+/)[1])
2160+
oritype = mocktype
21462161
}
21472162

21482163
if (/\sdata\s*=\s*"|\sdata-type=/.test(x)) {
@@ -2207,7 +2222,7 @@ function getMockInfo(x, mark, y) {
22072222
mocktype = 'base64'
22082223
}
22092224
} else if (/\smock-request-body\s/.test(x)) {
2210-
if (targetApp === 'surge-module') {
2225+
if (targetApp === 'surge-module' || targetApp === 'shadowrocket-module') {
22112226
const e = `暂不支持 Mock Request Body:\n${x}`
22122227
console.log(e)
22132228
shNotify(e)

Rewrite-Parser.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ if (binaryInfo != null && binaryInfo.length > 0) {
560560

561561
if (/\s((request|response)-body-json-jq)\s|\surl\sjsonjq-(response|request)-body/.test(_x)) {
562562
let [_, regex, type, value] = _x.match(/^(.*?)\s+?(?:url\s+?jsonjq-)?(request|response)-body(?:-json-jq)?\s+?(.*?)\s*$/)
563-
if (jqEnabled && (isSurgeiOS || isStashiOS)) {
563+
if (jqEnabled && (isSurgeiOS || isStashiOS || isShadowrocket)) {
564564
const jqPath = value.match(/jq-path="(.+?)"/)?.[1]
565565
if (jqPath) {
566566
if (/^https?:\/\//.test(jqPath)) {
@@ -1302,11 +1302,25 @@ if (binaryInfo != null && binaryInfo.length > 0) {
13021302
const { type, regex, value } = rwbodyBox[i]
13031303
if (isSurgeiOS || isShadowrocket){
13041304
BodyRewrite.push(`${type} ${regex} ${value}`)
1305-
}else if (isLooniOS){
1306-
let type2 = /request/.test(type) ? 'request-body-json-jq' : 'response-body-json-jq';
1305+
} else if (isLooniOS) {
1306+
let type2
1307+
switch (type) {
1308+
case 'http-request':
1309+
type2 = 'request-body-replace-regex'
1310+
break
1311+
case 'http-response':
1312+
type2 = 'response-body-replace-regex'
1313+
break
1314+
case 'http-request-jq':
1315+
type2 = 'request-body-json-jq'
1316+
break
1317+
case 'http-response-jq':
1318+
type2 = 'response-body-json-jq'
1319+
break
1320+
}
13071321
URLRewrite.push(`${regex} ${type2} ${value}`)
13081322
}
1309-
1323+
13101324
}
13111325

13121326
//headerRewrite输出
@@ -1400,13 +1414,13 @@ if (binaryInfo != null && binaryInfo.length > 0) {
14001414
case 'loon-plugin':
14011415
URLRewrite.push(
14021416
mark +
1403-
noteK +
1404-
mockptn +
1405-
' mock-response-body' +
1406-
mocktype +
1407-
(mockBox[i].datapath ? ` data-path=${mockBox[i].datapath}` : ` data="${mockBox[i].data}"`) +
1408-
mockstatus +
1409-
(mockBox[i].mockbase64 ? ' mock-data-is-base64=true' : '')
1417+
noteK +
1418+
mockptn +
1419+
' mock-response-body' +
1420+
mocktype +
1421+
(mockBox[i].datapath ? ` data-path=${mockBox[i].datapath}` : mockBox[i].data ? ` data="${mockBox[i].data}"` : mockBox[i].mockurl ? ` data-path=${mockBox[i].mockurl}` : "") +
1422+
mockstatus +
1423+
(mockBox[i].mockbase64 ? ' mock-data-is-base64=true' : '')
14101424
)
14111425
break
14121426
} //switch
@@ -2143,6 +2157,7 @@ function getMockInfo(x, mark, y) {
21432157
mockurl = x.split(/\s+echo-response\s+/)[2]
21442158
mocktype = 'file'
21452159
mockheader = '&contentType=' + encodeURIComponent(x.split(/\s+echo-response\s+/)[1])
2160+
oritype = mocktype
21462161
}
21472162

21482163
if (/\sdata\s*=\s*"|\sdata-type=/.test(x)) {
@@ -2207,7 +2222,7 @@ function getMockInfo(x, mark, y) {
22072222
mocktype = 'base64'
22082223
}
22092224
} else if (/\smock-request-body\s/.test(x)) {
2210-
if (targetApp === 'surge-module') {
2225+
if (targetApp === 'surge-module' || targetApp === 'shadowrocket-module') {
22112226
const e = `暂不支持 Mock Request Body:\n${x}`
22122227
console.log(e)
22132228
shNotify(e)

0 commit comments

Comments
 (0)