bugfix: 解决success、abort、redirect拦截器跨域问题。

release-2.0.0.2
王良 2025-05-09 17:06:25 +08:00
parent 785e7be4d1
commit b582ac63ad
3 changed files with 30 additions and 6 deletions

View File

@ -5,10 +5,18 @@ module.exports = {
const { rOptions, log } = context
if (interceptOpt.abort === true || interceptOpt.abort === 'true') {
res.writeHead(403, {
const headers = {
'Content-Type': 'text/plain; charset=utf-8',
'DS-Interceptor': 'abort',
})
}
// headers.Access-Control-Allow-*:避免跨域问题
if (rOptions.headers.origin) {
headers['Access-Control-Allow-Credentials'] = 'true'
headers['Access-Control-Allow-Origin'] = rOptions.headers.origin
}
res.writeHead(403, headers)
res.write(
'DevSidecar 403: Request abort.\n\n'
+ ' This request is matched by abort intercept.\n\n'

View File

@ -9,10 +9,18 @@ module.exports = {
// 获取重定向目标地址
const redirect = proxyApi.buildTargetUrl(rOptions, interceptOpt.redirect, interceptOpt, matched)
res.writeHead(302, {
const headers = {
'Location': redirect,
'DS-Interceptor': 'redirect',
})
}
// headers.Access-Control-Allow-*:避免跨域问题
if (rOptions.headers.origin) {
headers['Access-Control-Allow-Credentials'] = 'true'
headers['Access-Control-Allow-Origin'] = rOptions.headers.origin
}
res.writeHead(302, headers)
res.end()
const url = `${rOptions.method}${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${req.url}`

View File

@ -5,10 +5,18 @@ module.exports = {
const { rOptions, log } = context
if (interceptOpt.success === true || interceptOpt.success === 'true') {
res.writeHead(200, {
const headers = {
'Content-Type': 'text/plain; charset=utf-8',
'DS-Interceptor': 'success',
})
}
// headers.Access-Control-Allow-*:避免跨域问题
if (rOptions.headers.origin) {
headers['Access-Control-Allow-Credentials'] = 'true'
headers['Access-Control-Allow-Origin'] = rOptions.headers.origin
}
res.writeHead(200, headers)
res.write(
'DevSidecar 200: Request success.\n\n'
+ ' This request is matched by success intercept.\n\n'