Skip to content

Commit f2bb26a

Browse files
author
Bruce A. Grobler
committed
Cleanup commented code, and null check objects on failure, add error logging.
1 parent 264ce7c commit f2bb26a

File tree

5 files changed

+57
-70
lines changed

5 files changed

+57
-70
lines changed

demo/package-lock.json

Lines changed: 30 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
"tns-platform-declarations": "latest",
2323
"typescript": "latest"
2424
}
25-
}
25+
}

https.ios.js

Lines changed: 23 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

https.ios.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
//
2-
3-
import * as application from 'tns-core-modules/application'
4-
import {HttpRequestOptions, Headers, HttpResponse} from 'tns-core-modules/http'
51
import {isDefined, isNullOrUndefined, isObject} from 'tns-core-modules/utils/types'
62
import * as Https from './https.common'
73

@@ -20,18 +16,13 @@ policies.def.allowInvalidCertificates = true;
2016
policies.def.validatesDomainName = false;
2117

2218
export 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

9765
function AFFailure(resolve, reject, task: NSURLSessionDataTask, error: NSError) {

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,5 @@
5454
"tns-platform-declarations": "latest",
5555
"typescript": "latest"
5656
},
57-
"dependencies": {
58-
"nativescript-https": "latest"
59-
}
57+
"dependencies": {}
6058
}

0 commit comments

Comments
 (0)