mirror of
https://github.com/yattee/yattee.git
synced 2026-02-20 17:59:45 +00:00
Yattee v2 rewrite
This commit is contained in:
40
Yattee/Services/Networking/HTTPClientFactory.swift
Normal file
40
Yattee/Services/Networking/HTTPClientFactory.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// HTTPClientFactory.swift
|
||||
// Yattee
|
||||
//
|
||||
// Factory for creating HTTPClient instances with appropriate SSL settings.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Factory for creating HTTPClient instances based on instance SSL settings.
|
||||
final class HTTPClientFactory: Sendable {
|
||||
private let sessionFactory: URLSessionFactory
|
||||
|
||||
init(sessionFactory: URLSessionFactory = .shared) {
|
||||
self.sessionFactory = sessionFactory
|
||||
}
|
||||
|
||||
/// Creates an HTTPClient configured for the given instance's SSL requirements.
|
||||
/// - Parameter instance: The instance to create a client for.
|
||||
/// - Returns: An HTTPClient with appropriate SSL settings.
|
||||
func createClient(for instance: Instance) -> HTTPClient {
|
||||
let session = sessionFactory.session(allowInvalidCertificates: instance.allowInvalidCertificates)
|
||||
return HTTPClient(session: session)
|
||||
}
|
||||
|
||||
/// Creates an HTTPClient with explicit SSL settings.
|
||||
/// - Parameter allowInvalidCertificates: Whether to bypass SSL certificate validation.
|
||||
/// - Returns: An HTTPClient with the specified SSL settings.
|
||||
func createClient(allowInvalidCertificates: Bool) -> HTTPClient {
|
||||
let session = sessionFactory.session(allowInvalidCertificates: allowInvalidCertificates)
|
||||
return HTTPClient(session: session)
|
||||
}
|
||||
|
||||
/// Creates an HTTPClient with low network priority for background/prefetch work.
|
||||
/// - Returns: An HTTPClient configured with `.background` network service type.
|
||||
func createLowPriorityClient() -> HTTPClient {
|
||||
let session = sessionFactory.lowPrioritySession()
|
||||
return HTTPClient(session: session)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user