@@ -46,6 +46,58 @@ extension HTTPConnectionPool {
46
46
}
47
47
48
48
extension HTTPConnectionPool . ConnectionFactory {
49
+
50
+ func makeConnection( for pool: HTTPConnectionPool , connectionID: HTTPConnectionPool . Connection . ID , eventLoop: EventLoop , logger: Logger ) {
51
+ var logger = logger
52
+ logger [ metadataKey: " ahc-connection " ] = " \( connectionID) "
53
+
54
+ let future : EventLoopFuture < ( Channel , HTTPVersion ) >
55
+
56
+ if self . key. scheme. isProxyable, let proxy = self . clientConfiguration. proxy {
57
+ future = self . makeHTTPProxyChannel ( proxy, connectionID: connectionID, eventLoop: eventLoop, logger: logger)
58
+ } else {
59
+ future = self . makeChannel ( eventLoop: eventLoop, logger: logger)
60
+ }
61
+
62
+ future. whenComplete { result in
63
+ do {
64
+ switch result {
65
+ case . success( let ( channel, . http1_0) ) , . success( let ( channel, . http1_1) ) :
66
+ let connection = try HTTP1Connection (
67
+ channel: channel,
68
+ connectionID: connectionID,
69
+ configuration: self . clientConfiguration,
70
+ delegate: pool,
71
+ logger: logger
72
+ )
73
+ pool. http1ConnectionCreated ( connection)
74
+ case . success( let ( channel, . http2) ) :
75
+ let http2Connection = try HTTP2Connection (
76
+ channel: channel,
77
+ connectionID: connectionID,
78
+ delegate: pool,
79
+ logger: logger
80
+ )
81
+
82
+ http2Connection. readyToAcceptConnectionsFuture. whenComplete { result in
83
+ switch result {
84
+ case . success:
85
+ pool. http2ConnectionCreated ( http2Connection)
86
+ case . failure( let error) :
87
+ pool. failedToCreateHTTPConnection ( connectionID, error: error)
88
+ }
89
+ }
90
+ case . failure( let error) :
91
+ throw error
92
+ default :
93
+ preconditionFailure ( " Unexpected new http version " )
94
+ }
95
+ } catch {
96
+ pool. failedToCreateHTTPConnection ( connectionID, error: error)
97
+ }
98
+ }
99
+ }
100
+
49
101
func makeBestChannel( connectionID: HTTPConnectionPool . Connection . ID , eventLoop: EventLoop , logger: Logger ) -> EventLoopFuture < ( Channel , HTTPVersion ) > {
50
102
if self . key. scheme. isProxyable, let proxy = self . clientConfiguration. proxy {
51
103
return self . makeHTTPProxyChannel ( proxy, connectionID: connectionID, eventLoop: eventLoop, logger: logger)
0 commit comments