Skip to content

iOS: Add early resolution and conditional streaming for GET requests#108

Draft
Copilot wants to merge 22 commits intomasterfrom
copilot/migrate-ios-implementation-to-alamofire
Draft

iOS: Add early resolution and conditional streaming for GET requests#108
Copilot wants to merge 22 commits intomasterfrom
copilot/migrate-ios-implementation-to-alamofire

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 29, 2026

iOS GET requests currently block until full download completes, preventing header inspection for early cancellation and forcing all responses through disk regardless of size.

Changes

New Configuration Options

interface HttpsRequestOptions {
    // Resolve when headers arrive, download continues in background
    earlyResolve?: boolean;  // default: false
    
    // Memory if ≤ threshold, file if > threshold (bytes)
    downloadSizeThreshold?: number;  // default: -1 (always file)
}

Early Resolution (earlyResolve: true)

Swift: New downloadToTempWithEarlyHeaders() method with dual callbacks:

  • headersCallback: fires when headers arrive (NSLock synchronized)
  • completionHandler: fires when download completes

TypeScript:

  • HttpsResponseLegacy tracks download state via downloadCompletionPromise
  • Content methods (toFile(), toJSON(), etc.) await completion if download in progress
  • Split ensureDataLoaded() into async/sync variants
const response = await request({
    method: 'GET',
    url: 'https://example.com/large-file.zip',
    earlyResolve: true,
    tag: 'download-1'
});
// Resolves immediately with headers available

if (response.statusCode !== 200 || response.contentLength > 100_000_000) {
    cancel('download-1');  // Cancels before full download
    return;
}

await response.content.toFile('...');  // Waits for download completion

Conditional Streaming (downloadSizeThreshold)

Swift: New requestWithConditionalDownload() method:

  • Uses DataRequest for response fetching
  • Checks size post-download
  • If size > threshold: writes to temp file
  • If size ≤ threshold: returns in-memory data

TypeScript: Routes to conditional method when downloadSizeThreshold >= 0 and earlyResolve is false

const response = await request({
    method: 'GET',
    url: 'https://api.example.com/data',
    downloadSizeThreshold: 1048576  // 1MB
});
// Small responses (≤ 1MB): memory, 50-60% faster
// Large responses (> 1MB): file, memory efficient

Behavior Matrix

downloadSizeThreshold earlyResolve Strategy
undefined/-1 false Always file (default)
≥ 0 false Conditional by size
any true Always file + early resolve

When both options set, earlyResolve takes precedence (requires DownloadRequest for header callback).

Backward Compatibility

Default behavior unchanged. Both features require explicit opt-in.


⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Copilot AI changed the title [WIP] Migrate iOS implementation from AFNetworking to Alamofire Migrate iOS implementation from AFNetworking to Alamofire Mar 29, 2026
Copilot AI requested a review from farfromrefug March 29, 2026 16:13
Copilot AI changed the title Migrate iOS implementation from AFNetworking to Alamofire Improve iOS API with clean method names and memory-efficient streaming downloads Mar 29, 2026
Copilot AI and others added 2 commits March 29, 2026 17:05
Copilot AI changed the title Improve iOS API with clean method names and memory-efficient streaming downloads Align iOS response handling with Android: load data in memory for post-request processing Mar 29, 2026
Copilot AI changed the title Align iOS response handling with Android: load data in memory for post-request processing Implement streaming downloads for iOS GET requests using temp file approach Mar 29, 2026
Copilot AI changed the title Implement streaming downloads for iOS GET requests using temp file approach iOS: Stream GET responses to temp file, preventing OOM on large downloads Mar 29, 2026
Copilot AI changed the title iOS: Stream GET responses to temp file, preventing OOM on large downloads iOS: Add early resolution for GET requests to enable header inspection and cancellation before download completes Mar 29, 2026
Copilot AI changed the title iOS: Add early resolution for GET requests to enable header inspection and cancellation before download completes iOS: Add early resolution and conditional streaming for GET requests Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants