mirror of
https://github.com/swift-server/async-http-client.git
synced 2026-06-02 07:37:34 +00:00
Add "debug initializer" hook for channels (#801)
Motivation: As requested in #596, it can be handy to have a lower-level access to channels (HTTP/1 connection, HTTP/2 connection, or HTTP/2 stream) to enable a more fine-grained interaction for, say, observability, testing, etc. Modifications: - Add 3 new properties (`http1_1ConnectionDebugInitializer`, `http2ConnectionDebugInitializer` and `http2StreamChannelDebugInitializer`) to `HTTPClient.Configuration` with access to the respective channels. These properties are of `Optional` type `@Sendable (Channel) -> EventLoopFuture<Void>` and are called when creating a connection/stream. Result: Provides APIs for a lower-level access to channels. --------- Co-authored-by: Cory Benfield <lukasa@apple.com> Co-authored-by: David Nadoba <d_nadoba@apple.com> Co-authored-by: George Barnett <gbarnett@apple.com>
This commit is contained in:
co-authored by
Cory Benfield
David Nadoba
George Barnett
parent
373862aa09
commit
a3d00a65b9
@@ -85,7 +85,19 @@ extension HTTPConnectionPool.ConnectionFactory {
|
||||
decompression: self.clientConfiguration.decompression,
|
||||
logger: logger
|
||||
)
|
||||
requester.http1ConnectionCreated(connection)
|
||||
|
||||
if let connectionDebugInitializer = self.clientConfiguration.http1_1ConnectionDebugInitializer {
|
||||
connectionDebugInitializer(channel).whenComplete { debugInitializerResult in
|
||||
switch debugInitializerResult {
|
||||
case .success:
|
||||
requester.http1ConnectionCreated(connection)
|
||||
case .failure(let error):
|
||||
requester.failedToCreateHTTPConnection(connectionID, error: error)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
requester.http1ConnectionCreated(connection)
|
||||
}
|
||||
} catch {
|
||||
requester.failedToCreateHTTPConnection(connectionID, error: error)
|
||||
}
|
||||
@@ -96,11 +108,34 @@ extension HTTPConnectionPool.ConnectionFactory {
|
||||
delegate: http2ConnectionDelegate,
|
||||
decompression: self.clientConfiguration.decompression,
|
||||
maximumConnectionUses: self.clientConfiguration.maximumUsesPerConnection,
|
||||
logger: logger
|
||||
logger: logger,
|
||||
streamChannelDebugInitializer:
|
||||
self.clientConfiguration.http2StreamChannelDebugInitializer
|
||||
).whenComplete { result in
|
||||
switch result {
|
||||
case .success((let connection, let maximumStreams)):
|
||||
requester.http2ConnectionCreated(connection, maximumStreams: maximumStreams)
|
||||
if let connectionDebugInitializer = self.clientConfiguration.http2ConnectionDebugInitializer {
|
||||
connectionDebugInitializer(channel).whenComplete {
|
||||
debugInitializerResult in
|
||||
switch debugInitializerResult {
|
||||
case .success:
|
||||
requester.http2ConnectionCreated(
|
||||
connection,
|
||||
maximumStreams: maximumStreams
|
||||
)
|
||||
case .failure(let error):
|
||||
requester.failedToCreateHTTPConnection(
|
||||
connectionID,
|
||||
error: error
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
requester.http2ConnectionCreated(
|
||||
connection,
|
||||
maximumStreams: maximumStreams
|
||||
)
|
||||
}
|
||||
case .failure(let error):
|
||||
requester.failedToCreateHTTPConnection(connectionID, error: error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user