Skip to content

Commit 62b9e99

Browse files
bugfix: abort 和 success 拦截器,浅拷贝headers配置,避免配置被覆盖。
1 parent 0d0e514 commit 62b9e99

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

packages/mitmproxy/src/lib/interceptor/impl/req/abort.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@ module.exports = {
3232

3333
// status
3434
const status = response.status || 403
35-
response.status = status
3635

3736
// body
3837
const body = response.html || response.json || response.script || response.css || response.text || response.body
3938
|| `DevSidecar ${status}: Request abort.\n\n`
4039
+ ' This request is matched by abort intercept.\n\n'
4140
+ ` 因配置abort拦截器,本请求直接返回${status}禁止访问。`
4241

43-
// headers
44-
const headers = response.headers || {}
45-
response.headers = headers
42+
// headers:浅拷贝配置中的 headers,避免将 origin 等请求级数据写入共享的拦截器配置对象
43+
const headers = { ...(response.headers || {}) }
4644
headers['DS-Interceptor'] = 'abort'
4745
// headers.Content-Type
4846
if (status !== 204) {

packages/mitmproxy/src/lib/interceptor/impl/req/success.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,15 @@ module.exports = {
3737

3838
// status
3939
const status = response.status || 200
40-
response.status = status
4140

4241
// body
4342
const body = response.html || response.json || response.script || response.css || response.text || response.body
4443
|| `DevSidecar ${status}: Request success.\n\n`
4544
+ ' This request is matched by success intercept.\n\n'
4645
+ ` 因配置success拦截器,本请求直接返回${status}成功。`
4746

48-
// headers
49-
const headers = response.headers || {}
50-
response.headers = headers
47+
// headers:浅拷贝配置中的 headers,避免将 origin 等请求级数据写入共享的拦截器配置对象
48+
const headers = { ...(response.headers || {}) }
5149
headers['DS-Interceptor'] = 'success'
5250
// headers.Content-Type
5351
if (status !== 204) {

0 commit comments

Comments
 (0)