diff --git a/Makefile b/Makefile index b7c1c36a..d63a7a40 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ define buildtest xcodebuild -scheme $(project)-Package \ -derivedDataPath .derived-data/$(1) -resultBundleVersion 3 -resultBundlePath ./TestResults/$(1) -destination '$(2)' \ -enableCodeCoverage=YES -enableAddressSanitizer=YES -enableThreadSanitizer=YES -enableUndefinedBehaviorSanitizer=YES \ + -clonedSourcePackagesDirPath ${HOME}/.xcode-pkgs \ test | xcbeautify endef diff --git a/Sources/Sunday/EventSource.swift b/Sources/Sunday/EventSource.swift index 3575b478..17afec80 100644 --- a/Sources/Sunday/EventSource.swift +++ b/Sources/Sunday/EventSource.swift @@ -494,7 +494,7 @@ public class EventSource { return } - // Quietly close dure to Task or URLTask cancellation + // Quietly close due to Task or URLTask cancellation if isCancellationError(error: error) { fireErrorEvent(error: error) close() diff --git a/Sources/Sunday/NetworkRequestFactory.swift b/Sources/Sunday/NetworkRequestFactory.swift index a20aea56..e67fc9ce 100644 --- a/Sources/Sunday/NetworkRequestFactory.swift +++ b/Sources/Sunday/NetworkRequestFactory.swift @@ -26,6 +26,8 @@ private let eventStreamLogger = Logger.for(category: "Event Streams") public class NetworkRequestFactory: RequestFactory { + public static let eventRequestTimeoutInterval: TimeInterval = 15 * 60 // 15 minutes + public let baseURL: URI.Template public let session: NetworkSession public let eventSession: NetworkSession @@ -34,6 +36,7 @@ public class NetworkRequestFactory: RequestFactory { public let mediaTypeEncoders: MediaTypeEncoders public let mediaTypeDecoders: MediaTypeDecoders public let pathEncoders: PathEncoders + public let eventRequestTimeoutInterval: TimeInterval private var problemTypes: [String: Problem.Type] = [:] public init( @@ -44,6 +47,7 @@ public class NetworkRequestFactory: RequestFactory { requestQueue: DispatchQueue = .global(qos: .utility), mediaTypeEncoders: MediaTypeEncoders = .default, mediaTypeDecoders: MediaTypeDecoders = .default, + eventRequestTimeoutInterval: TimeInterval = NetworkRequestFactory.eventRequestTimeoutInterval, pathEncoders: PathEncoders = .default ) { self.baseURL = baseURL @@ -54,6 +58,7 @@ public class NetworkRequestFactory: RequestFactory { self.mediaTypeEncoders = mediaTypeEncoders self.mediaTypeDecoders = mediaTypeDecoders self.pathEncoders = pathEncoders + self.eventRequestTimeoutInterval = eventRequestTimeoutInterval } public convenience init( @@ -452,7 +457,11 @@ public class NetworkRequestFactory: RequestFactory { return EventSource(queue: requestQueue) { headers in guard let request = try await requestFactory() else { return nil } - return try self.eventSession.dataEventStream(for: request.adding(httpHeaders: headers)) + let updatedRequest = + request + .adding(httpHeaders: headers) + .with(timeoutInterval: self.eventRequestTimeoutInterval) + return try self.eventSession.dataEventStream(for: updatedRequest) } }