responseInterceptor static method
dynamic
responseInterceptor(
- Response options,
- ResponseInterceptorHandler handler
拦截接口返回的header信息
Implementation
static dynamic responseInterceptor(Response options, ResponseInterceptorHandler handler) async {
String? responseAuth = options.headers.value("authorization");
if (TextUtils.isNotEmpty(responseAuth)) {
//if the header is present, then compare it with the Shared Prefs key
String? localAuth = UserManager().getAuth();
_log("intercept auth >>> from: ${options.requestOptions.path}");
_log("intercept auth >>> new auth: $responseAuth");
_log("intercept auth >>> old auth: $localAuth");
// if the value is the same as the header, continue with the request
if (responseAuth != localAuth) {
UserManager().updateAuth(responseAuth);
_log("responseInterceptor update auth: $responseAuth");
}
}
// TODO 更新域名 header返回的domain version待定
String? domainVersion = options.headers.value("domainVersion");
if (domainVersion != null) {
DomainManager().updateDomain(domainVersion ?? "");
}
handler.next(options);
return options;
}