@@ -235,7 +235,7 @@ class HTTP1ConnectionProvider {
235
235
logger. trace ( " opening fresh connection (found matching but inactive connection) " ,
236
236
metadata: [ " ahc-dead-connection " : " \( connection) " ] )
237
237
self . makeChannel ( preference: waiter. preference) . whenComplete { result in
238
- self . connect ( result, waiter: waiter, replacing : connection , logger: logger)
238
+ self . connect ( result, waiter: waiter, logger: logger)
239
239
}
240
240
}
241
241
}
@@ -252,7 +252,7 @@ class HTTP1ConnectionProvider {
252
252
metadata: [ " ahc-old-connection " : " \( connection) " ,
253
253
" ahc-waiter " : " \( waiter) " ] )
254
254
self . makeChannel ( preference: waiter. preference) . whenComplete { result in
255
- self . connect ( result, waiter: waiter, replacing : connection , logger: logger)
255
+ self . connect ( result, waiter: waiter, logger: logger)
256
256
}
257
257
}
258
258
case . park( let connection) :
@@ -308,21 +308,15 @@ class HTTP1ConnectionProvider {
308
308
return waiter. promise. futureResult
309
309
}
310
310
311
- func connect( _ result: Result < Channel , Error > ,
312
- waiter: Waiter < Connection > ,
313
- replacing closedConnection: Connection ? = nil ,
314
- logger: Logger ) {
311
+ func connect( _ result: Result < Channel , Error > , waiter: Waiter < Connection > , logger: Logger ) {
315
312
let action : Action < Connection >
316
313
switch result {
317
314
case . success( let channel) :
318
315
logger. trace ( " successfully created connection " ,
319
316
metadata: [ " ahc-connection " : " \( channel) " ] )
320
317
let connection = Connection ( channel: channel, provider: self )
321
318
action = self . lock. withLock {
322
- if let closedConnection = closedConnection {
323
- self . state. drop ( connection: closedConnection)
324
- }
325
- return self . state. offer ( connection: connection)
319
+ self . state. offer ( connection: connection)
326
320
}
327
321
328
322
switch action {
@@ -367,7 +361,7 @@ class HTTP1ConnectionProvider {
367
361
// This is needed to start a new stack, otherwise, since this is called on a previous
368
362
// future completion handler chain, it will be growing indefinitely until the connection is closed.
369
363
// We might revisit this when https://github.com/apple/swift-nio/issues/970 is resolved.
370
- connection. channel . eventLoop. execute {
364
+ connection. eventLoop. execute {
371
365
self . execute ( action, logger: logger)
372
366
}
373
367
}
@@ -418,59 +412,7 @@ class HTTP1ConnectionProvider {
418
412
}
419
413
420
414
private func makeChannel( preference: HTTPClient . EventLoopPreference ) -> EventLoopFuture < Channel > {
421
- let channelEventLoop = preference. bestEventLoop ?? self . eventLoop
422
- let requiresTLS = self . key. scheme. requiresTLS
423
- let bootstrap : NIOClientTCPBootstrap
424
- do {
425
- bootstrap = try NIOClientTCPBootstrap . makeHTTPClientBootstrapBase ( on: channelEventLoop, host: self . key. host, port: self . key. port, requiresTLS: requiresTLS, configuration: self . configuration)
426
- } catch {
427
- return channelEventLoop. makeFailedFuture ( error)
428
- }
429
-
430
- let channel : EventLoopFuture < Channel >
431
- switch self . key. scheme {
432
- case . http, . https:
433
- let address = HTTPClient . resolveAddress ( host: self . key. host, port: self . key. port, proxy: self . configuration. proxy)
434
- channel = bootstrap. connect ( host: address. host, port: address. port)
435
- case . unix, . http_unix, . https_unix:
436
- channel = bootstrap. connect ( unixDomainSocketPath: self . key. unixPath)
437
- }
438
-
439
- return channel. flatMap { channel in
440
- let requiresSSLHandler = self . configuration. proxy != nil && self . key. scheme. requiresTLS
441
- let handshakePromise = channel. eventLoop. makePromise ( of: Void . self)
442
-
443
- channel. pipeline. addSSLHandlerIfNeeded ( for: self . key, tlsConfiguration: self . configuration. tlsConfiguration, addSSLClient: requiresSSLHandler, handshakePromise: handshakePromise)
444
-
445
- return handshakePromise. futureResult. flatMap {
446
- channel. pipeline. addHTTPClientHandlers ( leftOverBytesStrategy: . forwardBytes)
447
- } . flatMap {
448
- #if canImport(Network)
449
- if #available( OSX 10 . 14 , iOS 12 . 0 , tvOS 12 . 0 , watchOS 6 . 0 , * ) , bootstrap. underlyingBootstrap is NIOTSConnectionBootstrap {
450
- return channel. pipeline. addHandler ( HTTPClient . NWErrorHandler ( ) , position: . first)
451
- }
452
- #endif
453
- return channel. eventLoop. makeSucceededFuture ( ( ) )
454
- } . flatMap {
455
- switch self . configuration. decompression {
456
- case . disabled:
457
- return channel. eventLoop. makeSucceededFuture ( ( ) )
458
- case . enabled( let limit) :
459
- let decompressHandler = NIOHTTPResponseDecompressor ( limit: limit)
460
- return channel. pipeline. addHandler ( decompressHandler)
461
- }
462
- } . map {
463
- channel
464
- }
465
- } . flatMapError { error in
466
- #if canImport(Network)
467
- var error = error
468
- if #available( OSX 10 . 14 , iOS 12 . 0 , tvOS 12 . 0 , watchOS 6 . 0 , * ) , bootstrap. underlyingBootstrap is NIOTSConnectionBootstrap {
469
- error = HTTPClient . NWErrorHandler. translateError ( error)
470
- }
471
- #endif
472
- return channelEventLoop. makeFailedFuture ( error)
473
- }
415
+ return NIOClientTCPBootstrap . makeHTTP1Channel ( destination: self . key, eventLoop: self . eventLoop, configuration: self . configuration, preference: preference)
474
416
}
475
417
476
418
/// A `Waiter` represents a request that waits for a connection when none is
0 commit comments