Skip to content

Commit

Permalink
fix: interceptor
Browse files Browse the repository at this point in the history
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
  • Loading branch information
bggRGjQaUbCoE committed Feb 4, 2025
1 parent b4abb58 commit a40c773
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions lib/http/interceptor.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:io';

import 'package:PiliPlus/http/api.dart';
import 'package:PiliPlus/pages/mine/controller.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
Expand Down Expand Up @@ -31,7 +29,24 @@ class ApiInterceptor extends Interceptor {

@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
if (MineController.anonymity.value) {
void onRemoveCookie() {
options.headers.remove('x-bili-mid');
options.headers.remove('x-bili-aurora-eid');
options.headers.remove('x-bili-aurora-zone');
options.headers['cookie'] = '';
options.queryParameters.remove('access_key');
options.queryParameters.remove('csrf');
options.queryParameters.remove('csrf_token');
if (options.data is Map) {
options.data.remove('access_key');
options.data.remove('csrf');
options.data.remove('csrf_token');
}
}

if (options.extra['clearCookie'] == true) {
onRemoveCookie();
} else if (MineController.anonymity.value) {
String uri = options.uri.toString();
for (var i in anonymityList) {
// 如果请求的url包含无痕列表中的url,则清空cookie
Expand All @@ -40,22 +55,11 @@ class ApiInterceptor extends Interceptor {
if (index == -1) continue;
if (uri.lastIndexOf('/') >= index + i.length) continue;
//SmartDialog.showToast('触发无痕模式\n\n$i\n\n${options.uri}');
options.headers[HttpHeaders.cookieHeader] = "";
if (options.data != null && options.data.csrf != null) {
options.data.csrf = "";
}
onRemoveCookie();
break;
}
}
if (options.extra['clearCookie'] == true) {
options.headers['x-bili-mid'] = '';
options.headers['x-bili-aurora-eid'] = '';
options.headers['x-bili-aurora-zone'] = '';
options.headers[HttpHeaders.cookieHeader] = '';
if (options.data != null && options.data.csrf != null) {
options.data.csrf = '';
}
}

handler.next(options);
}

Expand Down

0 comments on commit a40c773

Please sign in to comment.