|
15 | 15 | import Connect |
16 | 16 | import Foundation |
17 | 17 | import NIOConcurrencyHelpers |
18 | | -@preconcurrency import NIOCore // TODO: Remove once `ChannelHandler` is `Sendable` |
| 18 | +@preconcurrency import NIOCore |
19 | 19 | import NIOHTTP1 |
20 | | -@preconcurrency import NIOHTTP2 // TODO: Remove once `HTTP2StreamMultiplexer` is `Sendable` |
| 20 | +import NIOHTTP2 |
21 | 21 | import NIOPosix |
22 | | -import NIOSSL |
| 22 | +@preconcurrency import NIOSSL |
23 | 23 | import os.log |
24 | 24 |
|
25 | 25 | /// HTTP client powered by Swift NIO which supports trailers (unlike URLSession). |
@@ -193,22 +193,23 @@ open class NIOHTTPClient: Connect.HTTPClientInterface, @unchecked Sendable { |
193 | 193 | self.state = .connecting |
194 | 194 | self.bootstrap |
195 | 195 | .connect(host: self.host, port: self.port) |
196 | | - .flatMap { channel -> EventLoopFuture<(Channel, HTTP2StreamMultiplexer)> in |
197 | | - return channel.pipeline |
198 | | - .handler(type: HTTP2StreamMultiplexer.self) |
199 | | - .map { (channel, $0) } |
200 | | - } |
201 | 196 | .whenComplete { [weak self] result in |
202 | | - switch result { |
203 | | - case .success((let channel, let multiplexer)): |
204 | | - channel.closeFuture.whenComplete { [weak self] _ in |
205 | | - self?.lock.withLock { self?.state = .disconnected } |
206 | | - } |
207 | | - self?.lock.withLock { |
208 | | - self?.state = .connected(channel: channel, multiplexer: multiplexer) |
209 | | - self?.flushOrFailPendingRequests(using: multiplexer) |
| 197 | + do { |
| 198 | + switch result { |
| 199 | + case .success(let channel): |
| 200 | + let multiplexer = try channel.pipeline.syncOperations |
| 201 | + .handler(type: HTTP2StreamMultiplexer.self) |
| 202 | + channel.closeFuture.whenComplete { [weak self] _ in |
| 203 | + self?.lock.withLock { self?.state = .disconnected } |
| 204 | + } |
| 205 | + self?.lock.withLock { |
| 206 | + self?.state = .connected(channel: channel, multiplexer: multiplexer) |
| 207 | + self?.flushOrFailPendingRequests(using: multiplexer) |
| 208 | + } |
| 209 | + case .failure(let error): |
| 210 | + throw error |
210 | 211 | } |
211 | | - case .failure(let error): |
| 212 | + } catch let error { |
212 | 213 | os_log(.error, "NIOHTTPClient disconnected: %@", "\(error)") |
213 | 214 | self?.lock.withLock { |
214 | 215 | self?.state = .disconnected |
|
0 commit comments