Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ class HybridNitroCronet: HybridNitroCronetSpec {
private static let session: URLSession = {
let config = URLSessionConfiguration.default
config.requestCachePolicy = .useProtocolCachePolicy
config.urlCache = URLCache(
memoryCapacity: 32 * 1024 * 1024,
diskCapacity: 100 * 1024 * 1024,
diskPath: "nitrofetch_urlcache"
)
config.urlCache = NitroURLCache.shared
return NitroURLSession.make(configuration: config)
}()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@
private static let session: URLSession = {
let config = URLSessionConfiguration.default
config.requestCachePolicy = .useProtocolCachePolicy
config.urlCache = URLCache(memoryCapacity: 32 * 1024 * 1024,
diskCapacity: 100 * 1024 * 1024,
diskPath: "nitrofetch_urlcache")
config.urlCache = NitroURLCache.shared
return NitroURLSession.make(configuration: config)
}()

Expand Down Expand Up @@ -140,7 +138,7 @@
if let key = findPrefetchKey(req) {
// If a prefetched result is fresh, return immediately
if let cached = FetchCache.getResultIfFresh(key, maxAgeMs: Int64(req.prefetchCacheTtlMs ?? 5_000)) {
var headers = cached.headers ?? []

Check warning on line 141 in packages/react-native-nitro-fetch/ios/HybridNitroFetchClient.swift

View workflow job for this annotation

GitHub Actions / Harness iOS

left side of nil coalescing operator '??' has non-optional type '[NitroHeader]' (aka 'Array<margelo.nitro.nitrofetch.NitroHeader>'), so the right side is never used
headers.append(NitroHeader(key: "nitroPrefetched", value: "true"))
return NitroResponse(url: cached.url,
status: cached.status,
Expand All @@ -159,7 +157,7 @@
switch result {
case .success(let res):
// Mirror Android: mark response as coming from prefetch
var headers = res.headers ?? []

Check warning on line 160 in packages/react-native-nitro-fetch/ios/HybridNitroFetchClient.swift

View workflow job for this annotation

GitHub Actions / Harness iOS

left side of nil coalescing operator '??' has non-optional type '[NitroHeader]' (aka 'Array<margelo.nitro.nitrofetch.NitroHeader>'), so the right side is never used
headers.append(NitroHeader(key: "nitroPrefetched", value: "true"))
let wrapped = NitroResponse(url: res.url,
status: res.status,
Expand Down Expand Up @@ -341,7 +339,7 @@
throw NSError(domain: "NitroFetch", code: -3, userInfo: [NSLocalizedDescriptionKey: "Invalid URL: \(req.url)"])
}
var r = URLRequest(url: url)
if let m = req.method?.rawValue { r.httpMethod = reqToHttpMethod(req) }

Check warning on line 342 in packages/react-native-nitro-fetch/ios/HybridNitroFetchClient.swift

View workflow job for this annotation

GitHub Actions / Harness iOS

value 'm' was defined but never used; consider replacing with boolean test
if let headers = req.headers {
for h in headers { r.addValue(h.value, forHTTPHeaderField: h.key) }
}
Expand Down
8 changes: 8 additions & 0 deletions packages/react-native-nitro-fetch/ios/NitroURLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import Foundation
/// Keeps authentication challenges observable by delegate-based networking middleware.
private final class NitroURLSessionDelegate: NSObject, URLSessionDelegate {}

enum NitroURLCache {
static let shared = URLCache(
memoryCapacity: 32 * 1024 * 1024,
diskCapacity: 100 * 1024 * 1024,
diskPath: "nitrofetch_urlcache"
)
}

enum NitroURLSession {
static let shared = make(configuration: .default)

Expand Down
Loading