|
1 | 1 | import { File, ImageSource, Utils } from '@nativescript/core'; |
2 | | -import { CacheOptions, HttpsFormDataParam, HttpsRequest, HttpsRequestOptions, HttpsResponse, HttpsResponseLegacy, HttpsSSLPinningOptions } from '.'; |
| 2 | +import { CacheOptions, HttpsFormDataParam, HttpsRequest, HttpsRequestOptions, HttpsResponse, HttpsSSLPinningOptions, HttpsResponseLegacy as IHttpsResponseLegacy } from '.'; |
3 | 3 | import { getFilenameFromUrl, parseJSON } from './request.common'; |
4 | 4 | export { addInterceptor, addNetworkInterceptor } from './request.common'; |
5 | 5 |
|
@@ -90,9 +90,9 @@ function getData(data) { |
90 | 90 | return content; |
91 | 91 | } |
92 | 92 |
|
93 | | -class HttpsResponseLegacyAndroid implements HttpsResponseLegacy { |
| 93 | +class HttpsResponseLegacy implements IHttpsResponseLegacy { |
94 | 94 | // private callback?: com.nativescript.https.OkhttpResponse.OkHttpResponseAsyncCallback; |
95 | | - constructor(private data: NSDictionary<string, any> & NSData & NSArray<any>, private url: string) {} |
| 95 | + constructor(private data: NSDictionary<string, any> & NSData & NSArray<any>, public contentLength, private url: string) {} |
96 | 96 | toArrayBufferAsync(): Promise<ArrayBuffer> { |
97 | 97 | throw new Error('Method not implemented.'); |
98 | 98 | } |
@@ -230,6 +230,7 @@ function AFFailure(resolve, reject, task: NSURLSessionDataTask, error: NSError, |
230 | 230 | let getHeaders = () => ({}); |
231 | 231 | const sendi = ({ |
232 | 232 | task, |
| 233 | + contentLength: task.countOfBytesReceived, |
233 | 234 | reason: error.localizedDescription, |
234 | 235 | get headers() { |
235 | 236 | return getHeaders(); |
@@ -265,11 +266,12 @@ function AFFailure(resolve, reject, task: NSURLSessionDataTask, error: NSError, |
265 | 266 | failure.description = '@nativescript-community/https > Invalid SSL certificate! ' + error.description; |
266 | 267 | } |
267 | 268 | sendi.failure = failure; |
268 | | - sendi.content = new HttpsResponseLegacyAndroid(data, url); |
| 269 | + sendi.content = new HttpsResponseLegacy(data, sendi.contentLength, url); |
269 | 270 | resolve(sendi); |
270 | 271 | } else { |
271 | 272 | const content: any = { |
272 | 273 | body: parsedData, |
| 274 | + contentLength: sendi.contentLength, |
273 | 275 | description: error.description, |
274 | 276 | reason: error.localizedDescription, |
275 | 277 | url: failingURL ? failingURL.description : url, |
@@ -379,10 +381,12 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr |
379 | 381 | const success = function (task: NSURLSessionDataTask, data?: any) { |
380 | 382 | clearRunningRequest(); |
381 | 383 | // TODO: refactor this code with failure one. |
382 | | - const content = useLegacy ? new HttpsResponseLegacyAndroid(data, opts.url) : getData(data); |
| 384 | + const contentLength = task.countOfBytesReceived; |
| 385 | + const content = useLegacy ? new HttpsResponseLegacy(data, contentLength, opts.url) : getData(data); |
383 | 386 | let getHeaders = () => ({}); |
384 | 387 | const sendi = ({ |
385 | 388 | content, |
| 389 | + contentLength, |
386 | 390 | get headers() { |
387 | 391 | return getHeaders(); |
388 | 392 | }, |
|
0 commit comments