Skip to content

Commit f51ae1c

Browse files
committed
Implement feedback
1 parent 9e26b5e commit f51ae1c

File tree

5 files changed

+97
-110
lines changed

5 files changed

+97
-110
lines changed

Sources/AsyncHTTPClient/ConnectionPool/HTTP2/HTTP2Connection.swift

+15-20
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ final class HTTP2Connection {
3535
let multiplexer: HTTP2StreamMultiplexer
3636
let logger: Logger
3737

38+
/// A method with access to the stream channel that is called when creating the stream.
39+
let streamChannelDebugInitializer: (@Sendable (Channel) -> EventLoopFuture<Void>)?
40+
3841
/// the connection pool that created the connection
3942
let delegate: HTTP2ConnectionDelegate
4043

@@ -95,7 +98,8 @@ final class HTTP2Connection {
9598
decompression: HTTPClient.Decompression,
9699
maximumConnectionUses: Int?,
97100
delegate: HTTP2ConnectionDelegate,
98-
logger: Logger
101+
logger: Logger,
102+
streamChannelDebugInitializer: (@Sendable (Channel) -> EventLoopFuture<Void>)? = nil
99103
) {
100104
self.channel = channel
101105
self.id = connectionID
@@ -114,6 +118,7 @@ final class HTTP2Connection {
114118
)
115119
self.delegate = delegate
116120
self.state = .initialized
121+
self.streamChannelDebugInitializer = streamChannelDebugInitializer
117122
}
118123

119124
deinit {
@@ -128,34 +133,27 @@ final class HTTP2Connection {
128133
delegate: HTTP2ConnectionDelegate,
129134
decompression: HTTPClient.Decompression,
130135
maximumConnectionUses: Int?,
131-
logger: Logger
136+
logger: Logger,
137+
streamChannelDebugInitializer: (@Sendable (Channel) -> EventLoopFuture<Void>)? = nil
132138
) -> EventLoopFuture<(HTTP2Connection, Int)> {
133139
let connection = HTTP2Connection(
134140
channel: channel,
135141
connectionID: connectionID,
136142
decompression: decompression,
137143
maximumConnectionUses: maximumConnectionUses,
138144
delegate: delegate,
139-
logger: logger
145+
logger: logger,
146+
streamChannelDebugInitializer: streamChannelDebugInitializer
140147
)
141148
return connection._start0().map { maxStreams in (connection, maxStreams) }
142149
}
143150

144-
func executeRequest(
145-
_ request: HTTPExecutableRequest,
146-
streamChannelDebugInitializer: (@Sendable (Channel) -> EventLoopFuture<Void>)? = nil
147-
) {
151+
func executeRequest(_ request: HTTPExecutableRequest) {
148152
if self.channel.eventLoop.inEventLoop {
149-
self.executeRequest0(
150-
request,
151-
streamChannelDebugInitializer: streamChannelDebugInitializer
152-
)
153+
self.executeRequest0(request)
153154
} else {
154155
self.channel.eventLoop.execute {
155-
self.executeRequest0(
156-
request,
157-
streamChannelDebugInitializer: streamChannelDebugInitializer
158-
)
156+
self.executeRequest0(request)
159157
}
160158
}
161159
}
@@ -227,10 +225,7 @@ final class HTTP2Connection {
227225
return readyToAcceptConnectionsPromise.futureResult
228226
}
229227

230-
private func executeRequest0(
231-
_ request: HTTPExecutableRequest,
232-
streamChannelDebugInitializer: (@Sendable (Channel) -> EventLoopFuture<Void>)?
233-
) {
228+
private func executeRequest0(_ request: HTTPExecutableRequest) {
234229
self.channel.eventLoop.assertInEventLoop()
235230

236231
switch self.state {
@@ -271,7 +266,7 @@ final class HTTP2Connection {
271266
self.openStreams.remove(box)
272267
}
273268

274-
if let streamChannelDebugInitializer {
269+
if let streamChannelDebugInitializer = self.streamChannelDebugInitializer {
275270
return streamChannelDebugInitializer(channel).map { _ in
276271
channel.write(request, promise: nil)
277272
}

Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool+Factory.swift

+8-5
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ extension HTTPConnectionPool.ConnectionFactory {
8585
logger: logger
8686
)
8787

88-
if let debugInitializer
88+
if let connectionDebugInitializer
8989
= self.clientConfiguration.http1_1ConnectionDebugInitializer
9090
{
91-
debugInitializer(channel).whenComplete { debugInitializerResult in
91+
connectionDebugInitializer(channel).whenComplete { debugInitializerResult in
9292
switch debugInitializerResult {
9393
case .success:
9494
requester.http1ConnectionCreated(connection)
@@ -109,14 +109,17 @@ extension HTTPConnectionPool.ConnectionFactory {
109109
delegate: http2ConnectionDelegate,
110110
decompression: self.clientConfiguration.decompression,
111111
maximumConnectionUses: self.clientConfiguration.maximumUsesPerConnection,
112-
logger: logger
112+
logger: logger,
113+
streamChannelDebugInitializer:
114+
self.clientConfiguration.http2StreamChannelDebugInitializer
113115
).whenComplete { result in
114116
switch result {
115117
case .success((let connection, let maximumStreams)):
116-
if let debugInitializer
118+
if let connectionDebugInitializer
117119
= self.clientConfiguration.http2ConnectionDebugInitializer
118120
{
119-
debugInitializer(channel).whenComplete { debugInitializerResult in
121+
connectionDebugInitializer(channel).whenComplete {
122+
debugInitializerResult in
120123
switch debugInitializerResult {
121124
case .success:
122125
requester.http2ConnectionCreated(

Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift

+4-18
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,11 @@ final class HTTPConnectionPool:
321321
private func runUnlockedRequestAction(_ action: Actions.RequestAction.Unlocked) {
322322
switch action {
323323
case .executeRequest(let request, let connection):
324-
connection.executeRequest(
325-
request.req,
326-
http2StreamChannelDebugInitializer:
327-
self.clientConfiguration.http2StreamChannelDebugInitializer
328-
)
324+
connection.executeRequest(request.req)
329325

330326
case .executeRequests(let requests, let connection):
331327
for request in requests {
332-
connection.executeRequest(
333-
request.req,
334-
http2StreamChannelDebugInitializer:
335-
self.clientConfiguration.http2StreamChannelDebugInitializer
336-
)
328+
connection.executeRequest(request.req)
337329
}
338330

339331
case .failRequest(let request, let error):
@@ -661,18 +653,12 @@ extension HTTPConnectionPool {
661653
}
662654
}
663655

664-
fileprivate func executeRequest(
665-
_ request: HTTPExecutableRequest,
666-
http2StreamChannelDebugInitializer: (@Sendable (Channel) -> EventLoopFuture<Void>)?
667-
) {
656+
fileprivate func executeRequest(_ request: HTTPExecutableRequest) {
668657
switch self._ref {
669658
case .http1_1(let connection):
670659
return connection.executeRequest(request)
671660
case .http2(let connection):
672-
return connection.executeRequest(
673-
request,
674-
streamChannelDebugInitializer: http2StreamChannelDebugInitializer
675-
)
661+
return connection.executeRequest(request)
676662
case .__testOnly_connection:
677663
break
678664
}

Sources/AsyncHTTPClient/HTTPClient.swift

+33-49
Original file line numberDiff line numberDiff line change
@@ -866,13 +866,7 @@ public class HTTPClient {
866866
connectionPool: ConnectionPool = ConnectionPool(),
867867
proxy: Proxy? = nil,
868868
ignoreUncleanSSLShutdown: Bool = false,
869-
decompression: Decompression = .disabled,
870-
http1_1ConnectionDebugInitializer:
871-
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil,
872-
http2ConnectionDebugInitializer:
873-
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil,
874-
http2StreamChannelDebugInitializer:
875-
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil
869+
decompression: Decompression = .disabled
876870
) {
877871
self.tlsConfiguration = tlsConfiguration
878872
self.redirectConfiguration = redirectConfiguration ?? RedirectConfiguration()
@@ -883,9 +877,6 @@ public class HTTPClient {
883877
self.httpVersion = .automatic
884878
self.networkFrameworkWaitForConnectivity = true
885879
self.enableMultipath = false
886-
self.http1_1ConnectionDebugInitializer = http1_1ConnectionDebugInitializer
887-
self.http2ConnectionDebugInitializer = http2ConnectionDebugInitializer
888-
self.http2StreamChannelDebugInitializer = http2StreamChannelDebugInitializer
889880
}
890881

891882
public init(
@@ -894,13 +885,7 @@ public class HTTPClient {
894885
timeout: Timeout = Timeout(),
895886
proxy: Proxy? = nil,
896887
ignoreUncleanSSLShutdown: Bool = false,
897-
decompression: Decompression = .disabled,
898-
http1_1ConnectionDebugInitializer:
899-
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil,
900-
http2ConnectionDebugInitializer:
901-
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil,
902-
http2StreamChannelDebugInitializer:
903-
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil
888+
decompression: Decompression = .disabled
904889
) {
905890
self.init(
906891
tlsConfiguration: tlsConfiguration,
@@ -909,10 +894,7 @@ public class HTTPClient {
909894
connectionPool: ConnectionPool(),
910895
proxy: proxy,
911896
ignoreUncleanSSLShutdown: ignoreUncleanSSLShutdown,
912-
decompression: decompression,
913-
http1_1ConnectionDebugInitializer: http1_1ConnectionDebugInitializer,
914-
http2ConnectionDebugInitializer: http2ConnectionDebugInitializer,
915-
http2StreamChannelDebugInitializer: http2StreamChannelDebugInitializer
897+
decompression: decompression
916898
)
917899
}
918900

@@ -923,13 +905,7 @@ public class HTTPClient {
923905
maximumAllowedIdleTimeInConnectionPool: TimeAmount = .seconds(60),
924906
proxy: Proxy? = nil,
925907
ignoreUncleanSSLShutdown: Bool = false,
926-
decompression: Decompression = .disabled,
927-
http1_1ConnectionDebugInitializer:
928-
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil,
929-
http2ConnectionDebugInitializer:
930-
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil,
931-
http2StreamChannelDebugInitializer:
932-
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil
908+
decompression: Decompression = .disabled
933909
) {
934910
var tlsConfig = TLSConfiguration.makeClientConfiguration()
935911
tlsConfig.certificateVerification = certificateVerification
@@ -940,10 +916,7 @@ public class HTTPClient {
940916
connectionPool: ConnectionPool(idleTimeout: maximumAllowedIdleTimeInConnectionPool),
941917
proxy: proxy,
942918
ignoreUncleanSSLShutdown: ignoreUncleanSSLShutdown,
943-
decompression: decompression,
944-
http1_1ConnectionDebugInitializer: http1_1ConnectionDebugInitializer,
945-
http2ConnectionDebugInitializer: http2ConnectionDebugInitializer,
946-
http2StreamChannelDebugInitializer: http2StreamChannelDebugInitializer
919+
decompression: decompression
947920
)
948921
}
949922

@@ -955,13 +928,7 @@ public class HTTPClient {
955928
proxy: Proxy? = nil,
956929
ignoreUncleanSSLShutdown: Bool = false,
957930
decompression: Decompression = .disabled,
958-
backgroundActivityLogger: Logger?,
959-
http1_1ConnectionDebugInitializer:
960-
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil,
961-
http2ConnectionDebugInitializer:
962-
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil,
963-
http2StreamChannelDebugInitializer:
964-
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil
931+
backgroundActivityLogger: Logger?
965932
) {
966933
var tlsConfig = TLSConfiguration.makeClientConfiguration()
967934
tlsConfig.certificateVerification = certificateVerification
@@ -972,10 +939,7 @@ public class HTTPClient {
972939
connectionPool: ConnectionPool(idleTimeout: connectionPool),
973940
proxy: proxy,
974941
ignoreUncleanSSLShutdown: ignoreUncleanSSLShutdown,
975-
decompression: decompression,
976-
http1_1ConnectionDebugInitializer: http1_1ConnectionDebugInitializer,
977-
http2ConnectionDebugInitializer: http2ConnectionDebugInitializer,
978-
http2StreamChannelDebugInitializer: http2StreamChannelDebugInitializer
942+
decompression: decompression
979943
)
980944
}
981945

@@ -985,6 +949,26 @@ public class HTTPClient {
985949
timeout: Timeout = Timeout(),
986950
proxy: Proxy? = nil,
987951
ignoreUncleanSSLShutdown: Bool = false,
952+
decompression: Decompression = .disabled
953+
) {
954+
self.init(
955+
certificateVerification: certificateVerification,
956+
redirectConfiguration: redirectConfiguration,
957+
timeout: timeout,
958+
maximumAllowedIdleTimeInConnectionPool: .seconds(60),
959+
proxy: proxy,
960+
ignoreUncleanSSLShutdown: ignoreUncleanSSLShutdown,
961+
decompression: decompression
962+
)
963+
}
964+
965+
public init(
966+
tlsConfiguration: TLSConfiguration? = nil,
967+
redirectConfiguration: RedirectConfiguration? = nil,
968+
timeout: Timeout = Timeout(),
969+
connectionPool: ConnectionPool = ConnectionPool(),
970+
proxy: Proxy? = nil,
971+
ignoreUncleanSSLShutdown: Bool = false,
988972
decompression: Decompression = .disabled,
989973
http1_1ConnectionDebugInitializer:
990974
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil,
@@ -994,17 +978,17 @@ public class HTTPClient {
994978
(@Sendable (Channel) -> EventLoopFuture<Void>)? = nil
995979
) {
996980
self.init(
997-
certificateVerification: certificateVerification,
981+
tlsConfiguration: tlsConfiguration,
998982
redirectConfiguration: redirectConfiguration,
999983
timeout: timeout,
1000-
maximumAllowedIdleTimeInConnectionPool: .seconds(60),
984+
connectionPool: connectionPool,
1001985
proxy: proxy,
1002986
ignoreUncleanSSLShutdown: ignoreUncleanSSLShutdown,
1003-
decompression: decompression,
1004-
http1_1ConnectionDebugInitializer: http1_1ConnectionDebugInitializer,
1005-
http2ConnectionDebugInitializer: http2ConnectionDebugInitializer,
1006-
http2StreamChannelDebugInitializer: http2StreamChannelDebugInitializer
987+
decompression: decompression
1007988
)
989+
self.http1_1ConnectionDebugInitializer = http1_1ConnectionDebugInitializer
990+
self.http2ConnectionDebugInitializer = http2ConnectionDebugInitializer
991+
self.http2StreamChannelDebugInitializer = http2StreamChannelDebugInitializer
1008992
}
1009993
}
1010994

0 commit comments

Comments
 (0)