Skip to content

Commit 0ee4640

Browse files
committed
fix(ios): base URL for AFHTTPSessionManager
1 parent 8d03ad0 commit 0ee4640

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/https/request.android.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const peer: Ipeer = {
2222

2323
let cache: okhttp3.Cache;
2424
let forceCache = false;
25+
2526
export function setCache(options?: CacheOptions) {
2627
if (options) {
2728
forceCache = options.forceCache === true;
@@ -34,6 +35,7 @@ export function setCache(options?: CacheOptions) {
3435
getClient(undefined, true);
3536
}
3637
}
38+
3739
export function clearCache() {
3840
if (cache) {
3941
cache.evictAll();

src/https/request.common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function getFilenameFromUrl(url: string) {
1515

1616
return result;
1717
}
18+
1819
export function parseJSON(source: string): any {
1920
const src = source.trim();
2021
if (src.lastIndexOf(')') === src.length - 1) {
@@ -25,10 +26,13 @@ export function parseJSON(source: string): any {
2526
}
2627

2728
export const interceptors = [];
29+
2830
export function addInterceptor(interceptor) {
2931
interceptors.push(interceptor);
3032
}
33+
3134
export const networkInterceptors = [];
35+
3236
export function addNetworkInterceptor(interceptor) {
3337
networkInterceptors.push(interceptor);
3438
}

src/https/request.ios.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function setCache(options?: CacheOptions) {
1313
}
1414
NSURLCache.sharedURLCache = cache;
1515
}
16+
1617
export function clearCache() {
1718
NSURLCache.sharedURLCache.removeAllCachedResponses();
1819
}
@@ -31,7 +32,12 @@ const policies: Ipolicies = {
3132
policies.def.allowInvalidCertificates = true;
3233
policies.def.validatesDomainName = false;
3334

35+
const configuration = NSURLSessionConfiguration.defaultSessionConfiguration;
36+
let manager = AFHTTPSessionManager.alloc().initWithSessionConfiguration(configuration);
37+
3438
export function enableSSLPinning(options: HttpsSSLPinningOptions) {
39+
const url = NSURL.URLWithString(options.host);
40+
manager = AFHTTPSessionManager.alloc().initWithSessionConfiguration(configuration).initWithBaseURL(url);
3541
if (!policies.secure) {
3642
policies.secure = AFSecurityPolicy.policyWithPinningMode(AFSSLPinningMode.PublicKey);
3743
policies.secure.allowInvalidCertificates = Utils.isDefined(options.allowInvalidCertificates) ? options.allowInvalidCertificates : false;
@@ -298,8 +304,6 @@ function bodyToNative(cont) {
298304
}
299305
return dict;
300306
}
301-
const configuration = NSURLSessionConfiguration.defaultSessionConfiguration;
302-
const manager = AFHTTPSessionManager.alloc().initWithSessionConfiguration(configuration);
303307

304308
const runningRequests: { [k: string]: NSURLSessionDataTask } = {};
305309

@@ -308,10 +312,11 @@ export function cancelRequest(tag: string) {
308312
runningRequests[tag].cancel();
309313
}
310314
}
315+
311316
export function cancelAllRequests() {
312-
Object.values(runningRequests).forEach(request=>{
313-
request.cancel()
314-
})
317+
Object.values(runningRequests).forEach((request) => {
318+
request.cancel();
319+
});
315320
}
316321

317322
export function clearCookies() {
@@ -373,8 +378,8 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
373378

374379
const progress = opts.onProgress
375380
? (progress: NSProgress) => {
376-
opts.onProgress(progress.completedUnitCount, progress.totalUnitCount);
377-
}
381+
opts.onProgress(progress.completedUnitCount, progress.totalUnitCount);
382+
}
378383
: null;
379384
let task: NSURLSessionDataTask;
380385
const tag = opts.tag;
@@ -500,7 +505,8 @@ export function request(opts: HttpsRequestOptions, useLegacy: boolean = true) {
500505
}
501506
});
502507
}
503-
//Android only
508+
509+
// Android only
504510
export function getClient(opts: Partial<HttpsRequestOptions>) {
505511
return undefined;
506512
}

0 commit comments

Comments
 (0)