diff --git a/Sources/DZNetworking/Core/DZOAuthSession.swift b/Sources/DZNetworking/Core/DZOAuthSession.swift index 4f18f9c..6307ccf 100644 --- a/Sources/DZNetworking/Core/DZOAuthSession.swift +++ b/Sources/DZNetworking/Core/DZOAuthSession.swift @@ -7,7 +7,7 @@ import Foundation -enum OAuthError: LocalizedError { +enum OAuthError: LocalizedError, Sendable { /// an auth session is already in progress case activeAuthState /// an invalid or no state token was received in the oauth verification callback diff --git a/Sources/DZNetworking/Core/DZURLSession+Codable.swift b/Sources/DZNetworking/Core/DZURLSession+Codable.swift index 9029999..1771d08 100644 --- a/Sources/DZNetworking/Core/DZURLSession+Codable.swift +++ b/Sources/DZNetworking/Core/DZURLSession+Codable.swift @@ -28,6 +28,10 @@ extension DZURLSession { throw PublicError.expectedData } + if data.isEmpty { + return (nil, response) + } + let decoder = decoder ?? DZURLSession.decoder let object = try decoder.decode(T.self, from: data) return (object, response) @@ -48,6 +52,10 @@ extension DZURLSession { throw PublicError.expectedData } + if data.isEmpty { + return (nil, response) + } + let decoder = decoder ?? DZURLSession.decoder let object = try decoder.decode(T.self, from: data) return (object, response) @@ -68,6 +76,10 @@ extension DZURLSession { throw PublicError.expectedData } + if data.isEmpty { + return (nil, response) + } + let decoder = decoder ?? DZURLSession.decoder let object = try decoder.decode(T.self, from: data) return (object, response) diff --git a/Sources/DZNetworking/HTTPURLRQ/HTTPURLRQ.swift b/Sources/DZNetworking/HTTPURLRQ/HTTPURLRQ.swift index d6ba81f..f12879b 100644 --- a/Sources/DZNetworking/HTTPURLRQ/HTTPURLRQ.swift +++ b/Sources/DZNetworking/HTTPURLRQ/HTTPURLRQ.swift @@ -19,7 +19,7 @@ import AppKit #endif /// This is Swift port OMGHTTPURLRQ -struct HTTPURLRQ { +struct HTTPURLRQ: Sendable { static let userAgent: String = { var ua = "" let info = Bundle.main.infoDictionary @@ -28,13 +28,39 @@ struct HTTPURLRQ { #if canImport(UIKit) #if os(watchOS) - let scale = 2.0 - let device = WKInterfaceDevice.current().model - let systemVersion = WKInterfaceDevice.current().systemVersion + let scale: CGFloat = 2.0 + var device: String + var systemVersion: String + + if Thread.isMainThread { + device = WKInterfaceDevice.current().model + systemVersion = WKInterfaceDevice.current().systemVersion + } + else { + DispatchQueue.main.sync { + device = WKInterfaceDevice.current().model + systemVersion = WKInterfaceDevice.current().systemVersion + } + } #else - let scale = UIScreen.main.scale - let device = UIDevice.current.model - let systemVersion = UIDevice.current.systemVersion + var scale: CGFloat = 2.0 + var device: String = "" + var systemVersion: String = "" + + if Thread.isMainThread { + MainActor.assumeIsolated { + scale = UIScreen.main.scale + device = UIDevice.current.model + systemVersion = UIDevice.current.systemVersion + } + } + else { + DispatchQueue.main.sync { + scale = UIScreen.main.scale + device = UIDevice.current.model + systemVersion = UIDevice.current.systemVersion + } + } #endif #if os(tvOS) diff --git a/Sources/DZNetworking/Utilities/DZS3CredentialsManager.swift b/Sources/DZNetworking/Utilities/DZS3CredentialsManager.swift index 8a84892..ec584d4 100644 --- a/Sources/DZNetworking/Utilities/DZS3CredentialsManager.swift +++ b/Sources/DZNetworking/Utilities/DZS3CredentialsManager.swift @@ -8,24 +8,24 @@ import Foundation import CommonCrypto -public enum DZS3Error: LocalizedError { +public enum DZS3Error: LocalizedError, Sendable { case incompleteParamters } /// The Access-Control-List used for the uploaded object. Can be `public` or `private`, defaults to `public`. -public enum DZACL: String { +public enum DZACL: String, Sendable { case `private` case `public` } /// The S3 at-rest encryption used for the uploaded object. `none` by default. -public enum DZS3Encryption: String { +public enum DZS3Encryption: String, Sendable { case `none` case AES256 } /// Credentials manager for S3 operations -public struct DZS3CredentialsManager { +public struct DZS3CredentialsManager: Sendable { /// the `AWSAccessKey` public let key: String /// the `AWSSecretKey` @@ -174,9 +174,9 @@ public struct DZS3CredentialsManager { } } -private extension String { +extension String { - func sha256() -> String { + public func sha256() -> String { guard let data = self.data(using: .utf8) else { return "" } var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH)) data.withUnsafeBytes { @@ -204,8 +204,8 @@ private extension String { } } -private extension Data { - func toHexString() -> String { +extension Data { + public func toHexString() -> String { let hexString = self.map{ String(format:"%02x", $0) }.joined() return hexString }