@@ -13,6 +13,7 @@ export function setCache(options?: CacheOptions) {
1313 }
1414 NSURLCache . sharedURLCache = cache ;
1515}
16+
1617export function clearCache ( ) {
1718 NSURLCache . sharedURLCache . removeAllCachedResponses ( ) ;
1819}
@@ -31,7 +32,12 @@ const policies: Ipolicies = {
3132policies . def . allowInvalidCertificates = true ;
3233policies . def . validatesDomainName = false ;
3334
35+ const configuration = NSURLSessionConfiguration . defaultSessionConfiguration ;
36+ let manager = AFHTTPSessionManager . alloc ( ) . initWithSessionConfiguration ( configuration ) ;
37+
3438export 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
304308const runningRequests : { [ k : string ] : NSURLSessionDataTask } = { } ;
305309
@@ -308,10 +312,11 @@ export function cancelRequest(tag: string) {
308312 runningRequests [ tag ] . cancel ( ) ;
309313 }
310314}
315+
311316export function cancelAllRequests ( ) {
312- Object . values ( runningRequests ) . forEach ( request => {
313- request . cancel ( )
314- } )
317+ Object . values ( runningRequests ) . forEach ( ( request ) => {
318+ request . cancel ( ) ;
319+ } ) ;
315320}
316321
317322export 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
504510export function getClient ( opts : Partial < HttpsRequestOptions > ) {
505511 return undefined ;
506512}
0 commit comments