1- import { CancellablePromise , Http } from '../http/http' ;
2- import { HttpError , HttpRequestOptions , ProgressEvent } from '../http/http-request-common' ;
3- import { FileManager } from '../file/file' ;
4- import { isNullOrUndefined , isObject , isFunction } from '@nativescript/core/utils/types' ;
5- import { knownFolders , path as filePath , File as fsFile } from '@nativescript/core' ;
1+ import { CancellablePromise , Http } from '../http/http' ;
2+ import { HttpError , HttpRequestOptions , ProgressEvent } from '../http/http-request-common' ;
3+ import { FileManager } from '../file/file' ;
4+ import { isNullOrUndefined , isObject , isFunction } from '@nativescript/core/utils/types' ;
5+ import { knownFolders , path as filePath , File as fsFile } from '@nativescript/core' ;
66
77enum XMLHttpRequestResponseType {
88 empty = '' ,
@@ -126,7 +126,7 @@ export class TNSXMLHttpRequest {
126126 loaded : number ;
127127 total : number ;
128128 target : any ;
129- } = { lengthComputable : false , loaded : 0 , total : 0 , target : this } ;
129+ } = { lengthComputable : false , loaded : 0 , total : 0 , target : this } ;
130130
131131 private _headers : any ;
132132 private _responseURL : string = '' ;
@@ -150,6 +150,8 @@ export class TNSXMLHttpRequest {
150150 return this . _response ;
151151 }
152152
153+ private _didUserSetResponseType = false ;
154+
153155 get responseType ( ) : any {
154156 return this . _responseType ;
155157 }
@@ -286,6 +288,7 @@ export class TNSXMLHttpRequest {
286288 }
287289
288290 set responseType ( value : any ) {
291+ this . _didUserSetResponseType = true ;
289292 if (
290293 value === XMLHttpRequestResponseType . empty ||
291294 value in XMLHttpRequestResponseType
@@ -421,7 +424,7 @@ export class TNSXMLHttpRequest {
421424 this . emitEvent ( 'loadstart' , startEvent ) ;
422425
423426 this . _updateReadyStateChange ( this . LOADING ) ;
424-
427+
425428 FileManager . readFile ( path , { } , ( error , data ) => {
426429 if ( error ) {
427430 const errorEvent = new ProgressEvent (
@@ -449,7 +452,7 @@ export class TNSXMLHttpRequest {
449452
450453 this . _updateReadyStateChange ( this . DONE ) ;
451454 } else {
452- if ( ! this . responseType ) {
455+ if ( ! this . _didUserSetResponseType ) {
453456 this . _setResponseType ( ) ;
454457 }
455458 this . _status = 200 ;
@@ -692,11 +695,12 @@ export class TNSXMLHttpRequest {
692695
693696 this . _currentRequest
694697 . then ( ( res ) => {
695- this . _setResponseType ( ) ;
698+ if ( ! this . _didUserSetResponseType ) {
699+ this . _setResponseType ( ) ;
700+ }
696701 this . _status = res . statusCode ;
697702 this . _httpContent = res . content ;
698703 this . _responseURL = res . url ;
699-
700704 if ( this . responseType === XMLHttpRequestResponseType . json ) {
701705 if ( typeof res . content === 'string' ) {
702706 this . _responseText = res . content ;
@@ -1097,7 +1101,7 @@ export class Blob {
10971101 public slice ( start ?: number , end ?: number , type ?: string ) : Blob {
10981102 const slice = this . _buffer . slice ( start || 0 , end || this . _buffer . length ) ;
10991103
1100- return new Blob ( [ slice ] , { type : type } ) ;
1104+ return new Blob ( [ slice ] , { type : type } ) ;
11011105 }
11021106
11031107 public stream ( ) {
0 commit comments