@@ -591,15 +591,22 @@ public final class ResponseAccumulator: HTTPClientResponseDelegate {
591591 }
592592
593593 public func didReceiveHead( task: HTTPClient . Task < Response > , _ head: HTTPResponseHead ) -> EventLoopFuture < Void > {
594- self . state. withLockedValue {
594+ let responseTooBig : Bool
595+
596+ if self . requestMethod != . HEAD,
597+ let contentLength = head. headers. first ( name: " Content-Length " ) ,
598+ let announcedBodySize = Int ( contentLength) ,
599+ announcedBodySize > self . maxBodySize {
600+ responseTooBig = true
601+ } else {
602+ responseTooBig = false
603+ }
604+
605+ return self . state. withLockedValue {
595606 switch $0. state {
596607 case . idle:
597- if self . requestMethod != . HEAD,
598- let contentLength = head. headers. first ( name: " Content-Length " ) ,
599- let announcedBodySize = Int ( contentLength) ,
600- announcedBodySize > self . maxBodySize
601- {
602- let error = ResponseTooBigError ( maxBodySize: maxBodySize)
608+ if responseTooBig {
609+ let error = ResponseTooBigError ( maxBodySize: self . maxBodySize)
603610 $0. state = . error( error)
604611 return task. eventLoop. makeFailedFuture ( error)
605612 }
@@ -910,8 +917,7 @@ extension HTTPClient {
910917 ///
911918 /// Will be created by the library and could be used for obtaining
912919 /// `EventLoopFuture<Response>` of the execution or cancellation of the execution.
913- @preconcurrency
914- public final class Task < Response: Sendable > {
920+ public final class Task < Response> : Sendable {
915921 /// The `EventLoop` the delegate will be executed on.
916922 public let eventLoop : EventLoop
917923 /// The `Logger` used by the `Task` for logging.
@@ -939,14 +945,14 @@ extension HTTPClient {
939945 }
940946 }
941947
942- private let makeOrGetFileIOThreadPool : ( ) -> NIOThreadPool
948+ private let makeOrGetFileIOThreadPool : @ Sendable ( ) -> NIOThreadPool
943949
944950 /// The shared thread pool of a ``HTTPClient`` used for file IO. It is lazily created on first access.
945951 internal var fileIOThreadPool : NIOThreadPool {
946952 self . makeOrGetFileIOThreadPool ( )
947953 }
948954
949- init ( eventLoop: EventLoop , logger: Logger , makeOrGetFileIOThreadPool: @escaping ( ) -> NIOThreadPool ) {
955+ init ( eventLoop: EventLoop , logger: Logger , makeOrGetFileIOThreadPool: @escaping @ Sendable ( ) -> NIOThreadPool ) {
950956 self . eventLoop = eventLoop
951957 self . promise = eventLoop. makePromise ( )
952958 self . logger = logger
@@ -958,7 +964,7 @@ extension HTTPClient {
958964 eventLoop: EventLoop ,
959965 error: Error ,
960966 logger: Logger ,
961- makeOrGetFileIOThreadPool: @escaping ( ) -> NIOThreadPool
967+ makeOrGetFileIOThreadPool: @escaping @ Sendable ( ) -> NIOThreadPool
962968 ) -> Task < Response > {
963969 let task = self . init (
964970 eventLoop: eventLoop,
@@ -1017,15 +1023,6 @@ extension HTTPClient {
10171023 taskDelegate? . fail ( error)
10181024 }
10191025
1020- func succeed< Delegate: HTTPClientResponseDelegate > (
1021- promise: EventLoopPromise < Response > ? ,
1022- with value: Response ,
1023- delegateType: Delegate . Type ,
1024- closing: Bool
1025- ) {
1026- promise? . succeed ( value)
1027- }
1028-
10291026 func fail< Delegate: HTTPClientResponseDelegate > (
10301027 with error: Error ,
10311028 delegateType: Delegate . Type
@@ -1035,8 +1032,6 @@ extension HTTPClient {
10351032 }
10361033}
10371034
1038- extension HTTPClient . Task : @unchecked Sendable { }
1039-
10401035internal struct TaskCancelEvent { }
10411036
10421037// MARK: - RedirectHandler
0 commit comments