Skip to content

Commit 61235bb

Browse files
Update downloadToTemp calls to use new signatures
Agent-Logs-Url: https://github.com/nativescript-community/https/sessions/cb3011ae-c8b8-4453-9b0e-af75b9bb74ce Co-authored-by: farfromrefug <655344+farfromrefug@users.noreply.github.com>
1 parent d4f705d commit 61235bb

1 file changed

Lines changed: 56 additions & 51 deletions

File tree

src/https/request.ios.ts

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -751,19 +751,22 @@ export function createRequest(opts: HttpsRequestOptions): HttpsRequest {
751751
// Track the content object so we can update it when download completes
752752
let responseContent: HttpsResponseLegacy | undefined;
753753

754-
const downloadTask = manager.downloadToTempWithEarlyHeaders(
754+
if (tag) {
755+
runningRequests[tag] = requestId;
756+
}
757+
758+
manager.downloadToTempWithEarlyHeaders(
755759
opts.method,
756760
opts.url,
757761
dict,
758762
headers,
763+
requestId,
759764
sizeThreshold,
760765
progress,
761-
(response: NSURLResponse, contentLength: number) => {
766+
(httpResponse: NSHTTPURLResponse, contentLength: number) => {
762767
// Headers callback - resolve request early
763768
clearRunningRequest();
764769

765-
const httpResponse = response as NSHTTPURLResponse;
766-
767770
// Create response WITHOUT temp file path (download still in progress)
768771
responseContent = new HttpsResponseLegacy(null, contentLength, opts.url, undefined, downloadCompletionPromise);
769772
const content = responseContent;
@@ -793,63 +796,65 @@ export function createRequest(opts: HttpsRequestOptions): HttpsRequest {
793796
// Resolve immediately with headers
794797
resolve(sendi);
795798
},
796-
(response: NSURLResponse, tempFilePath: string, error: NSError) => {
797-
// Download completion callback
798-
if (error) {
799-
downloadCompletionReject(new Error(error.localizedDescription));
800-
} else {
801-
// Update the response content with temp file path
802-
if (responseContent) {
803-
(responseContent as any).tempFilePath = tempFilePath;
804-
}
805-
downloadCompletionResolve();
799+
(httpResponse: NSHTTPURLResponse, tempFilePath: string) => {
800+
// Download completion callback - success
801+
// Update the response content with temp file path
802+
if (responseContent) {
803+
(responseContent as any).tempFilePath = tempFilePath;
806804
}
805+
downloadCompletionResolve();
806+
},
807+
(httpResponse: NSHTTPURLResponse, error: NSError) => {
808+
// Download completion callback - failure
809+
downloadCompletionReject(new Error(error.localizedDescription));
807810
}
808811
);
809-
810-
task = downloadTask as any;
811812
} else {
812813
// Standard download: wait for full download before resolving
813-
const downloadTask = manager.downloadToTemp(opts.method, opts.url, dict, headers, progress, (response: NSURLResponse, tempFilePath: string, error: NSError) => {
814-
clearRunningRequest();
815-
if (error) {
816-
// Convert download task to data task for failure handling
817-
const dataTask = task as any as NSURLSessionTask;
818-
failure(dataTask, error);
819-
return;
820-
}
814+
if (tag) {
815+
runningRequests[tag] = requestId;
816+
}
817+
818+
manager.downloadToTemp(
819+
opts.method,
820+
opts.url,
821+
dict,
822+
headers,
823+
requestId,
824+
progress,
825+
(httpResponse: NSHTTPURLResponse, tempFilePath: string) => {
826+
clearRunningRequest();
821827

822-
const httpResponse = response as NSHTTPURLResponse;
823-
const contentLength = httpResponse?.expectedContentLength || 0;
828+
const contentLength = httpResponse?.expectedContentLength || 0;
824829

825-
// Create response with temp file path (no data loaded in memory yet)
826-
const content = new HttpsResponseLegacy(null, contentLength, opts.url, tempFilePath);
830+
// Create response with temp file path (no data loaded in memory yet)
831+
const content = new HttpsResponseLegacy(null, contentLength, opts.url, tempFilePath);
827832

828-
let getHeaders = () => ({});
829-
const sendi = {
830-
content,
831-
contentLength,
832-
get headers() {
833-
return getHeaders();
834-
}
835-
} as any as HttpsResponse;
836-
837-
if (!Utils.isNullOrUndefined(httpResponse)) {
838-
sendi.statusCode = httpResponse.statusCode;
839-
getHeaders = function () {
840-
const dict = httpResponse.allHeaderFields;
841-
if (dict) {
842-
const headers = {};
843-
dict.enumerateKeysAndObjectsUsingBlock((k, v) => (headers[k] = v));
844-
return headers;
833+
let getHeaders = () => ({});
834+
const sendi = {
835+
content,
836+
contentLength,
837+
get headers() {
838+
return getHeaders();
845839
}
846-
return null;
847-
};
848-
}
849-
resolve(sendi);
850-
});
840+
} as any as HttpsResponse;
851841

852-
task = downloadTask as any;
842+
if (!Utils.isNullOrUndefined(httpResponse)) {
843+
sendi.statusCode = httpResponse.statusCode;
844+
getHeaders = function () {
845+
const dict = httpResponse.allHeaderFields;
846+
if (dict) {
847+
const headers = {};
848+
dict.enumerateKeysAndObjectsUsingBlock((k, v) => (headers[k] = v));
849+
return headers;
850+
}
851+
return null;
852+
};
853+
}
854+
resolve(sendi);
855+
},
856+
failure
857+
);
853858
}
854859
} else {
855860
// For non-GET requests, use regular request (loads into memory)

0 commit comments

Comments
 (0)