@@ -52,6 +52,7 @@ class NSURLSessionTaskDelegateImpl extends NSObject
52
52
private _loadingSent : boolean ;
53
53
private _debuggerRequest ;
54
54
private _response ;
55
+
55
56
public static initWithDebuggerRequestResolveRejectCallbackHeadersLoadingListener (
56
57
debuggerRequest ,
57
58
request ,
@@ -99,20 +100,20 @@ class NSURLSessionTaskDelegateImpl extends NSObject
99
100
) {
100
101
// const method = this._request.HTTPMethod.toLowerCase();
101
102
if ( data ) {
102
- this . _data . appendData ( data ) ;
103
-
104
- const lastProgress : any = this . _lastProgress || {
105
- lengthComputable : false ,
106
- total : 0
107
- } ;
108
- lastProgress . loaded = this . _data . length ;
109
- if ( this . _onLoading && ! this . _loadingSent ) {
110
- this . _onLoading ( lastProgress ) ;
111
- this . _loadingSent = true ;
112
- }
113
- if ( this . _onProgress ) {
114
- this . _onProgress ( lastProgress ) ;
115
- }
103
+ this . _data . appendData ( data ) ;
104
+
105
+ const lastProgress : any = this . _lastProgress || {
106
+ lengthComputable : false ,
107
+ total : 0
108
+ } ;
109
+ lastProgress . loaded = this . _data . length ;
110
+ if ( this . _onLoading && ! this . _loadingSent ) {
111
+ this . _onLoading ( lastProgress ) ;
112
+ this . _loadingSent = true ;
113
+ }
114
+ if ( this . _onProgress ) {
115
+ this . _onProgress ( lastProgress ) ;
116
+ }
116
117
}
117
118
}
118
119
@@ -123,20 +124,20 @@ class NSURLSessionTaskDelegateImpl extends NSObject
123
124
totalBytesSent ,
124
125
totalBytesExpectedToSend
125
126
) {
126
- if ( this . _onLoading || this . _onProgress ) {
127
- this . _lastProgress = {
128
- lengthComputable : totalBytesExpectedToSend > - 1 ,
129
- loaded : totalBytesSent ,
130
- total : totalBytesExpectedToSend > - 1 ? totalBytesExpectedToSend : 0
131
- } ;
132
- if ( this . _onLoading && ! this . _loadingSent ) {
133
- this . _onLoading ( this . _lastProgress ) ;
134
- this . _loadingSent = true ;
135
- }
136
- if ( this . _onProgress ) {
137
- this . _onProgress ( this . _lastProgress ) ;
127
+ if ( this . _onLoading || this . _onProgress ) {
128
+ this . _lastProgress = {
129
+ lengthComputable : totalBytesExpectedToSend > - 1 ,
130
+ loaded : totalBytesSent ,
131
+ total : totalBytesExpectedToSend > - 1 ? totalBytesExpectedToSend : 0
132
+ } ;
133
+ if ( this . _onLoading && ! this . _loadingSent ) {
134
+ this . _onLoading ( this . _lastProgress ) ;
135
+ this . _loadingSent = true ;
136
+ }
137
+ if ( this . _onProgress ) {
138
+ this . _onProgress ( this . _lastProgress ) ;
139
+ }
138
140
}
139
- }
140
141
}
141
142
142
143
public URLSessionDataTaskDidReceiveResponseCompletionHandler (
@@ -223,7 +224,7 @@ class NSURLSessionTaskDelegateImpl extends NSObject
223
224
const isTextContentType = ( contentType : string ) : boolean => {
224
225
let result = false ;
225
226
for ( let i = 0 ; i < textTypes . length ; i ++ ) {
226
- if ( contentType . toLowerCase ( ) . indexOf ( textTypes [ i ] ) >= 0 ) {
227
+ if ( types . isString ( contentType ) && contentType . toLowerCase ( ) . indexOf ( textTypes [ i ] ) >= 0 ) {
227
228
result = true ;
228
229
break ;
229
230
}
@@ -257,7 +258,7 @@ class NSURLSessionTaskDelegateImpl extends NSObject
257
258
}
258
259
259
260
let returnType = 'text/plain' ;
260
- if ( acceptHeader != null ) {
261
+ if ( ! types . isNullOrUndefined ( acceptHeader ) && types . isString ( acceptHeader ) ) {
261
262
let acceptValues = acceptHeader . split ( ',' ) ;
262
263
let quality = [ ] ;
263
264
let defaultQuality = [ ] ;
@@ -284,19 +285,19 @@ class NSURLSessionTaskDelegateImpl extends NSObject
284
285
if ( isTextContentType ( returnType ) ) {
285
286
responseText = NSDataToString ( this . _data ) ;
286
287
content = responseText ;
287
- } else if ( returnType . indexOf ( 'application/json' ) > - 1 ) {
288
+ } else if ( types . isString ( returnType ) && returnType . indexOf ( 'application/json' ) > - 1 ) {
288
289
// @ts -ignore
289
290
try {
290
- responseText = NSDataToString ( this . _data ) ;
291
- content = JSON . parse ( responseText ) ;
292
- // content = deserialize(NSJSONSerialization.JSONObjectWithDataOptionsError(this._data, NSJSONReadingOptions.AllowFragments, null));
291
+ responseText = NSDataToString ( this . _data ) ;
292
+ content = JSON . parse ( responseText ) ;
293
+ // content = deserialize(NSJSONSerialization.JSONObjectWithDataOptionsError(this._data, NSJSONReadingOptions.AllowFragments, null));
293
294
} catch ( err ) {
294
- this . _reject ( {
295
- type : HttpError . Error ,
296
- ios : null ,
297
- message : err
298
- } ) ;
299
- return ;
295
+ this . _reject ( {
296
+ type : HttpError . Error ,
297
+ ios : null ,
298
+ message : err
299
+ } ) ;
300
+ return ;
300
301
}
301
302
} else {
302
303
content = this . _data ;
@@ -379,9 +380,9 @@ export class Http {
379
380
let domainDebugger ;
380
381
let debugRequest ;
381
382
if ( TNSHttpDebugging . enabled ) {
382
- domainDebugger = require ( 'tns-core-modules/debugger' ) ;
383
- const network = domainDebugger . getNetwork ( ) ;
384
- debugRequest = network && network . create ( ) ;
383
+ domainDebugger = require ( 'tns-core-modules/debugger' ) ;
384
+ const network = domainDebugger . getNetwork ( ) ;
385
+ debugRequest = network && network . create ( ) ;
385
386
}
386
387
387
388
const urlRequest = NSMutableURLRequest . requestWithURL (
0 commit comments