1- //
2-
3- import * as application from 'tns-core-modules/application'
4- import { HttpRequestOptions , Headers , HttpResponse } from 'tns-core-modules/http'
51import { isDefined , isNullOrUndefined , isObject } from 'tns-core-modules/utils/types'
62import * as Https from './https.common'
73
@@ -20,18 +16,13 @@ policies.def.allowInvalidCertificates = true;
2016policies . def . validatesDomainName = false ;
2117
2218export function enableSSLPinning ( options : Https . HttpsSSLPinningOptions ) {
23- // console.log('options', options)
2419 if ( ! policies . secure ) {
2520 policies . secure = AFSecurityPolicy . policyWithPinningMode ( AFSSLPinningMode . PublicKey ) ;
2621 let allowInvalidCertificates = ( isDefined ( options . allowInvalidCertificates ) ) ? options . allowInvalidCertificates : false ;
2722 policies . secure . allowInvalidCertificates = allowInvalidCertificates ;
2823 let validatesDomainName = ( isDefined ( options . validatesDomainName ) ) ? options . validatesDomainName : true ;
2924 policies . secure . validatesDomainName = validatesDomainName ;
3025 let data = NSData . dataWithContentsOfFile ( options . certificate ) ;
31- // console.log('data.description', data.description)
32- // console.log('data.bytes', data.bytes)
33- // console.log('data.base64Encoding()', data.base64Encoding())
34- // console.log('data.length', data.length)
3526 policies . secure . pinnedCertificates = NSSet . setWithObject ( data )
3627 }
3728 policies . secured = true ;
@@ -50,48 +41,25 @@ function AFSuccess(resolve, task: NSURLSessionDataTask, data: NSDictionary<strin
5041 // console.log('AFSuccess')
5142 let content : any ;
5243 if ( data && data . class ) {
53- // console.log('data.class().name', data.class().name)
5444 if ( data . enumerateKeysAndObjectsUsingBlock || data . class ( ) . name == 'NSArray' ) {
55- // content = {}
56- // data.enumerateKeysAndObjectsUsingBlock(function(k, v) {
57- // console.log('v.description', v.description)
58- // content[k] = v
59- // })
6045 let serial = NSJSONSerialization . dataWithJSONObjectOptionsError ( data , NSJSONWritingOptions . PrettyPrinted ) ;
6146 content = NSString . alloc ( ) . initWithDataEncoding ( serial , NSUTF8StringEncoding ) . toString ( )
62- // console.log('content', content)
6347 } else if ( data . class ( ) . name == 'NSData' ) {
6448 content = NSString . alloc ( ) . initWithDataEncoding ( data , NSASCIIStringEncoding ) . toString ( )
65- // } else if (data.class().name == 'NSArray') {
66- // content = []
67- // let i: number, len: number = data.count
68- // for (i = 0; i < len; i++) {
69- // let item
70- // let result: NSDictionary<string, any> = data[i]
71- // if (result.enumerateKeysAndObjectsUsingBlock) {
72- // item = {}
73- // result.enumerateKeysAndObjectsUsingBlock(function(k, v) {
74- // item[k] = v
75- // })
76- // } else {
77- // item = data[i]
78- // }
79- // content.push(item)
80- // }
8149 } else {
8250 content = data
8351 }
8452
8553 try {
86- content = JSON . parse ( content )
54+ content = JSON . parse ( content ) ;
8755 } catch ( e ) {
8856 }
8957
9058 } else {
9159 content = data
9260 }
9361
94- resolve ( { task, content} )
62+ resolve ( { task, content} ) ;
9563}
9664
9765function AFFailure ( resolve , reject , task : NSURLSessionDataTask , error : NSError ) {
0 commit comments