@
oneisall8955 #2
在使用过程中,会发现 siteproxy 会劫持 response body ,进行内容修改,主要是将内容包含链接的全替换成 b 域名前缀。
如 b 的 siteproxy 服务是
https://siteproxy.bhost.com请求原始 response body 是 {"url":"
https://www.baidu.com?q=siteproxy"}
则在 siteproxy 进行替换成 {"url":"
https://siteproxy.bhost.com/https/www.baidu.com?q=siteproxy"}
这可能不是 A 服务想要的。
通过修改 siteproxy 源码解决,修改项目的 Proxy.js ,注释掉 handleResponse 方法中的过滤替换代码即可。
如下:
```js
//# for(let key in regReplaceMap) {
//# myRe = new RegExp(key, 'g') // match group
//# body = body.replace(myRe, regReplaceMap[key])
//# }
//# logSave(`##### host:${host}`)
//# if (host) {
//# body = pathReplace({host, httpType, body}) //13ms
//# }
//# logSave(`2`)
//# logSave(`3`)
//# myRe = new RegExp(`/${httpType}/${host}/${httpType}/${host}/`, 'g') // match group
//# body = body.replace(myRe, `/${httpType}/${host}/`)
//#
//# logSave(`4`) //1ms
//# // put siteSpecificReplace at end
//# Object.keys(siteSpecificReplace).forEach( (site) => {
//# if (!req.url) {
//# return
//# }
//# if (req.url.indexOf(site) !== -1 || (req.headers['referer'] && req.headers['referer'].indexOf(site) !== -1)) {
//# keys = Object.keys(siteSpecificReplace[site])
//# keys.forEach( key => {
//# myRe = new RegExp(key, 'g') // match group
//# body = body.replace(myRe, siteSpecificReplace[site][key])
//# })
//# }
//# }) //17ms
//#
//# logSave(`5`)
//# if (gbFlag) {
//# body = iconv.encode(body, 'gbk')
//# }
//# //
googlevideo.com manual redirection
//# if (typeof(body) === 'string' && body.startsWith(`${httpprefix}://${serverName}`) && body.indexOf('
googlevideo.com') !== -1) {
//# // need to manually redirect it for youtube workaround.
//# console.log(`============== redirect
googlevideo.com`)
//# try {
//# res.setHeader('location', body) //0ms
//# } catch(e) {
//# logSave(`error: ${e}`)
//# return
//# }
//# res.statusCode = '302'
//# }
//# logSave(`5 after replacment,displayed string, body.length:${body.length}`)
```