Skip to content

Commit 49073c5

Browse files
committed
fix: android allow interceptors
1 parent 89948f9 commit 49073c5

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

src/https.android.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ function getClient(reload: boolean = false, timeout: number = 10): okhttp3.OkHtt
266266
}
267267

268268
const client = new okhttp3.OkHttpClient.Builder();
269+
Https.interceptors.forEach((interceptor) => client.addInterceptor(interceptor));
270+
Https.networkInterceptors.forEach((interceptor) => client.addNetworkInterceptor(interceptor));
269271
if (peer.enabled === true) {
270272
if (peer.host || peer.certificate) {
271273
const spec = okhttp3.ConnectionSpec.MODERN_TLS;

src/https.common.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,12 @@ export function parseJSON(source: string): any {
107107

108108
return JSON.parse(src);
109109
}
110+
111+
export const interceptors = [];
112+
export function addInterceptor(interceptor) {
113+
interceptors.push(interceptor);
114+
}
115+
export const networkInterceptors = [];
116+
export function addNetworkInterceptor(interceptor) {
117+
networkInterceptors.push(interceptor);
118+
}

src/https.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export function request(options: Https.HttpsRequestOptions): Promise<Https.Https
88
export function setCache(options?: Https.CacheOptions);
99
export function clearCache();
1010
export function createRequest(opts: Https.HttpsRequestOptions): Https.HttpsRequest;
11-
11+
export function addNetworkInterceptor(interceptor);
1212
export * from './https.common';

src/https.ios.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ export function createRequest(opts: Https.HttpsRequestOptions): Https.HttpsReque
351351

352352
const progress = opts.onProgress
353353
? (progress: NSProgress) => {
354-
opts.onProgress(progress.completedUnitCount, progress.totalUnitCount);
355-
}
354+
opts.onProgress(progress.completedUnitCount, progress.totalUnitCount);
355+
}
356356
: null;
357357
let task: NSURLSessionDataTask;
358358

0 commit comments

Comments
 (0)