@@ -387,7 +387,7 @@ class HttpsResponseLegacy implements IHttpsResponseLegacy {
387387 }
388388}
389389
390- function AFFailure ( resolve , reject , httpResponse : NSHTTPURLResponse , error : NSError , useLegacy : boolean , url ) {
390+ function AFFailure ( resolve , reject , httpResponse : NSHTTPURLResponse , error : NSError , url ) {
391391 if ( error . code === - 999 ) {
392392 return reject ( error ) ;
393393 }
@@ -419,40 +419,23 @@ function AFFailure(resolve, reject, httpResponse: NSHTTPURLResponse, error: NSEr
419419 const data : NSDictionary < string , any > & NSData & NSArray < any > = error . userInfo . valueForKey ( AFNetworkingOperationFailingURLResponseDataErrorKey ) ;
420420 const parsedData = getData ( data ) ;
421421 const failingURL = error . userInfo . objectForKey ( 'NSErrorFailingURLKey' ) ;
422- if ( useLegacy ) {
423- if ( ! sendi . statusCode ) {
424- return reject ( error ) ;
425- }
426- const failure : any = {
427- error,
428- description : error . description ,
429- reason : error . localizedDescription ,
430- url : failingURL ? failingURL . description : url
431- } ;
432- if ( policies . secured === true ) {
433- failure . description = '@nativescript-community/https > Invalid SSL certificate! ' + error . description ;
434- }
435- sendi . failure = failure ;
436- sendi . content = new HttpsResponseLegacy ( data , sendi . contentLength , url ) ;
437- resolve ( sendi ) ;
438- } else {
439- const response : any = {
440- error,
441- body : parsedData ,
442- contentLength : sendi . contentLength ,
443- description : error . description ,
444- reason : error . localizedDescription ,
445- url : failingURL ? failingURL . description : url
446- } ;
447-
448- if ( policies . secured === true ) {
449- response . description = '@nativescript-community/https > Invalid SSL certificate! ' + response . description ;
450- }
451- sendi . content = parsedData ;
452- sendi . response = response ;
453-
454- resolve ( sendi ) ;
422+
423+ // Always use legacy response
424+ if ( ! sendi . statusCode ) {
425+ return reject ( error ) ;
426+ }
427+ const failure : any = {
428+ error,
429+ description : error . description ,
430+ reason : error . localizedDescription ,
431+ url : failingURL ? failingURL . description : url
432+ } ;
433+ if ( policies . secured === true ) {
434+ failure . description = '@nativescript-community/https > Invalid SSL certificate! ' + error . description ;
455435 }
436+ sendi . failure = failure ;
437+ sendi . content = new HttpsResponseLegacy ( data , sendi . contentLength , url ) ;
438+ resolve ( sendi ) ;
456439}
457440
458441function bodyToNative ( cont ) {
@@ -490,7 +473,7 @@ export function clearCookies() {
490473 storage . deleteCookie ( cookie ) ;
491474 } ) ;
492475}
493- export function createRequest ( opts : HttpsRequestOptions , useLegacy : boolean = true ) : HttpsRequest {
476+ export function createRequest ( opts : HttpsRequestOptions ) : HttpsRequest {
494477 const type = opts . headers ?. [ 'Content-Type' ] ?? 'application/json' ;
495478 if ( type . startsWith ( 'application/json' ) ) {
496479 manager . requestSerializerWrapper . httpShouldHandleCookies = opts . cookiesEnabled !== false ;
@@ -572,7 +555,7 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
572555 clearRunningRequest ( ) ;
573556 const contentLength = response ?. expectedContentLength ?? 0 ;
574557 console . log ( 'run done' , contentLength ) ;
575- const content = useLegacy ? new HttpsResponseLegacy ( data , contentLength , opts . url ) : getData ( data ) ;
558+ const content = new HttpsResponseLegacy ( data , contentLength , opts . url ) ;
576559 let getHeaders = ( ) => ( { } ) ;
577560 const sendi = {
578561 content,
@@ -602,7 +585,7 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
602585 } ;
603586 const failure = function ( response : NSHTTPURLResponse , error : any ) {
604587 clearRunningRequest ( ) ;
605- AFFailure ( resolve , reject , response , error , useLegacy , opts . url ) ;
588+ AFFailure ( resolve , reject , response , error , opts . url ) ;
606589 } ;
607590 if ( type . startsWith ( 'multipart/form-data' ) ) {
608591 switch ( opts . method ) {
@@ -659,14 +642,10 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
659642 Object . keys ( heads ) . forEach ( ( k ) => {
660643 request . setValueForHTTPHeaderField ( heads [ k ] , k ) ;
661644 } ) ;
662- task = manager . uploadFile ( request , NSURL . fileURLWithPath ( opts . body . path ) , progress , ( response : NSURLResponse , responseObject : any , error : NSError ) => {
663- if ( error ) {
664- failure ( task , error ) ;
665- } else {
666- success ( task , responseObject ) ;
667- }
668- } ) ;
669- task . resume ( ) ;
645+ if ( tag ) {
646+ runningRequests [ tag ] = requestId ;
647+ }
648+ manager . uploadFile ( request , NSURL . fileURLWithPath ( opts . body . path ) , requestId , progress , success , failure ) ;
670649 } else {
671650 let data : NSData ;
672651 // TODO: add support for Buffers
@@ -682,14 +661,10 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
682661 Object . keys ( heads ) . forEach ( ( k ) => {
683662 request . setValueForHTTPHeaderField ( heads [ k ] , k ) ;
684663 } ) ;
685- task = manager . uploadData ( request , data , progress , ( response : NSURLResponse , responseObject : any , error : NSError ) => {
686- if ( error ) {
687- failure ( task , error ) ;
688- } else {
689- success ( task , responseObject ) ;
690- }
691- } ) ;
692- task . resume ( ) ;
664+ if ( tag ) {
665+ runningRequests [ tag ] = requestId ;
666+ }
667+ manager . uploadData ( request , data , requestId , progress , success , failure ) ;
693668 }
694669 } else {
695670 let dict = null ;
@@ -732,11 +707,9 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
732707
733708 // If we got a temp file path, response was saved to file (large)
734709 // If we got responseData, response is in memory (small)
735- const content = useLegacy
736- ? tempFilePath
737- ? new HttpsResponseLegacy ( null , contentLength , opts . url , tempFilePath )
738- : new HttpsResponseLegacy ( responseData , contentLength , opts . url )
739- : tempFilePath || responseData ;
710+ const content = tempFilePath
711+ ? new HttpsResponseLegacy ( null , contentLength , opts . url , tempFilePath )
712+ : new HttpsResponseLegacy ( responseData , contentLength , opts . url ) ;
740713
741714 let getHeaders = ( ) => ( { } ) ;
742715 const sendi = {
@@ -792,10 +765,8 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
792765 const httpResponse = response as NSHTTPURLResponse ;
793766
794767 // Create response WITHOUT temp file path (download still in progress)
795- if ( useLegacy ) {
796- responseContent = new HttpsResponseLegacy ( null , contentLength , opts . url , undefined , downloadCompletionPromise ) ;
797- }
798- const content = useLegacy ? responseContent : undefined ;
768+ responseContent = new HttpsResponseLegacy ( null , contentLength , opts . url , undefined , downloadCompletionPromise ) ;
769+ const content = responseContent ;
799770
800771 let getHeaders = ( ) => ( { } ) ;
801772 const sendi = {
@@ -852,7 +823,7 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
852823 const contentLength = httpResponse ?. expectedContentLength || 0 ;
853824
854825 // Create response with temp file path (no data loaded in memory yet)
855- const content = useLegacy ? new HttpsResponseLegacy ( null , contentLength , opts . url , tempFilePath ) : tempFilePath ;
826+ const content = new HttpsResponseLegacy ( null , contentLength , opts . url , tempFilePath ) ;
856827
857828 let getHeaders = ( ) => ( { } ) ;
858829 const sendi = {
@@ -891,10 +862,10 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
891862 }
892863 } ;
893864}
894- export function request ( opts : HttpsRequestOptions , useLegacy : boolean = true ) {
865+ export function request ( opts : HttpsRequestOptions ) {
895866 return new Promise ( ( resolve , reject ) => {
896867 try {
897- createRequest ( opts , useLegacy ) . run ( resolve , reject ) ;
868+ createRequest ( opts ) . run ( resolve , reject ) ;
898869 } catch ( error ) {
899870 reject ( error ) ;
900871 }
0 commit comments