Skip to content

Commit ba2271f

Browse files
committed
implemented onConfig
1 parent 69f240b commit ba2271f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ interface XhrErrorHandler extends XhrHandler {
9797
}
9898

9999
interface Proxy {
100+
onConfig?: (config: XhrRequestConfig, xhrProxy: Hooks) => boolean | void,
100101
onRequest?: (config: XhrRequestConfig, handler: XhrRequestHandler) => void,
101102
onResponse?: (response: XhrResponse, handler: XhrResponseHandler) => void,
102103
onError?: (err: XhrError, handler: XhrErrorHandler) => void,

src/xhr-proxy.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ var ErrorHandler = makeHandler(function (error) {
102102
});
103103

104104
function proxyAjax(proxy, win) {
105-
var onRequest = proxy.onRequest,
105+
var onConfig = proxy.onConfig,
106+
onRequest = null,
107+
onRequest_ = proxy.onRequest,
106108
onResponse = proxy.onResponse,
107109
onError = proxy.onError;
108110

@@ -187,6 +189,10 @@ function proxyAjax(proxy, win) {
187189
// 所以我们在send拦截函数中再手动调用open,因此返回true阻止xhr.open调用。
188190
//
189191
// 如果没有请求拦截器,则不用阻断xhr.open调用
192+
onRequest = onRequest_;
193+
if (onConfig) {
194+
if (onConfig(config, this) === false) onRequest = null;
195+
}
190196
if (onRequest) return true;
191197
},
192198
send: function (args, xhr) {

0 commit comments

Comments
 (0)