@@ -21,7 +21,8 @@ import struct Foundation.URLQueryItem
2121/// AsyncHTTPClient-based HTTP client implementation that conforms to SmithyHTTPAPI.HTTPClient
2222/// This implementation is thread-safe and supports concurrent request execution.
2323public final class SwiftNIOHTTPClient : SmithyHTTPAPI . HTTPClient {
24- public static let noOpSwiftNIOHTTPClientTelemetry = ClientRuntime . HttpTelemetry (
24+ public static let noOpSwiftNIOHTTPClientTelemetry =
25+ ClientRuntime . HttpTelemetry (
2526 httpScope: " SwiftNIOHTTPClient " ,
2627 telemetryProvider: ClientRuntime . DefaultTelemetry. provider
2728 )
@@ -39,17 +40,22 @@ public final class SwiftNIOHTTPClient: SmithyHTTPAPI.HTTPClient {
3940
4041 /// Creates a new `SwiftNIOHTTPClient`.
4142 ///
42- /// The client is created with its own internal `AsyncHTTPClient`, which is configured with system defaults.
43+ /// The client is created with its own internal `AsyncHTTPClient`,
44+ /// which is configured with system defaults.
4345 /// - Parameters:
44- /// - httpClientConfiguration: The configuration to use for the client's `AsyncHTTPClient` setup.
46+ /// - httpClientConfiguration: The configuration to use for the
47+ /// client's `AsyncHTTPClient` setup.
4548 /// - eventLoopGroup: The `EventLoopGroup` that the ``HTTPClient`` will use.
4649 public init (
4750 httpClientConfiguration: ClientRuntime . HttpClientConfiguration ,
4851 eventLoopGroup: ( any NIOCore . EventLoopGroup ) ? = nil
4952 ) {
5053 self . config = httpClientConfiguration
51- self . telemetry = httpClientConfiguration. telemetry ?? SwiftNIOHTTPClient . noOpSwiftNIOHTTPClientTelemetry
52- self . logger = self . telemetry. loggerProvider. getLogger ( name: " SwiftNIOHTTPClient " )
54+ self . telemetry = httpClientConfiguration. telemetry ??
55+ SwiftNIOHTTPClient . noOpSwiftNIOHTTPClientTelemetry
56+ self . logger = self . telemetry. loggerProvider. getLogger (
57+ name: " SwiftNIOHTTPClient "
58+ )
5359 self . tlsConfiguration = httpClientConfiguration. tlsConfiguration as? SwiftNIOHTTPClientTLSOptions
5460 self . allocator = ByteBufferAllocator ( )
5561
@@ -70,7 +76,10 @@ public final class SwiftNIOHTTPClient: SmithyHTTPAPI.HTTPClient {
7076 }
7177
7278 if let eventLoopGroup {
73- self . client = AsyncHTTPClient . HTTPClient ( eventLoopGroup: eventLoopGroup, configuration: clientConfig)
79+ self . client = AsyncHTTPClient . HTTPClient (
80+ eventLoopGroup: eventLoopGroup,
81+ configuration: clientConfig
82+ )
7483 } else {
7584 self . client = AsyncHTTPClient . HTTPClient ( configuration: clientConfig)
7685 }
@@ -80,7 +89,9 @@ public final class SwiftNIOHTTPClient: SmithyHTTPAPI.HTTPClient {
8089 try ? client. syncShutdown ( )
8190 }
8291
83- public func send( request: SmithyHTTPAPI . HTTPRequest ) async throws -> SmithyHTTPAPI . HTTPResponse {
92+ public func send(
93+ request: SmithyHTTPAPI . HTTPRequest
94+ ) async throws -> SmithyHTTPAPI . HTTPResponse {
8495 let telemetryContext = telemetry. contextManager. current ( )
8596 let tracer = telemetry. tracerProvider. getTracer (
8697 scope: telemetry. tracerScope
@@ -92,7 +103,8 @@ public final class SwiftNIOHTTPClient: SmithyHTTPAPI.HTTPClient {
92103 name: telemetry. spanName,
93104 initialAttributes: telemetry. spanAttributes,
94105 spanKind: SpanKind . internal,
95- parentContext: telemetryContext)
106+ parentContext: telemetryContext
107+ )
96108 defer {
97109 span. end ( )
98110 }
@@ -114,13 +126,15 @@ public final class SwiftNIOHTTPClient: SmithyHTTPAPI.HTTPClient {
114126 telemetry. requestsQueuedDuration. record (
115127 value: queuedEnd - queuedStart,
116128 attributes: Attributes ( ) ,
117- context: telemetryContext)
129+ context: telemetryContext
130+ )
118131 // END - smithy.client.http.requests.queued_duration
119132
120133 // Update connection and request usage metrics
121134 telemetry. updateHTTPMetricsUsage { httpMetricsUsage in
122135 // TICK - smithy.client.http.connections.limit
123- // Note: AsyncHTTPClient doesn't expose connection pool configuration publicly
136+ // Note: AsyncHTTPClient doesn't expose connection pool
137+ // configuration publicly
124138 httpMetricsUsage. connectionsLimit = 0
125139
126140 // TICK - smithy.client.http.connections.usage
@@ -139,7 +153,8 @@ public final class SwiftNIOHTTPClient: SmithyHTTPAPI.HTTPClient {
139153 telemetry. connectionsUptime. record (
140154 value: Date ( ) . timeIntervalSinceReferenceDate - connectionUptimeStart,
141155 attributes: Attributes ( ) ,
142- context: telemetryContext)
156+ context: telemetryContext
157+ )
143158 }
144159
145160 let httpMethod = request. method. rawValue
@@ -152,22 +167,35 @@ public final class SwiftNIOHTTPClient: SmithyHTTPAPI.HTTPClient {
152167 let nioResponse = try await client. execute ( nioRequest, timeout: timeout)
153168
154169 // Convert NIO response to Smithy HTTPResponse
155- let statusCode = HTTPStatusCode ( rawValue: Int ( nioResponse. status. code) ) ?? . insufficientStorage
170+ let statusCode = HTTPStatusCode (
171+ rawValue: Int ( nioResponse. status. code)
172+ ) ?? . insufficientStorage
156173 var headers = Headers ( )
157174 for (name, value) in nioResponse. headers {
158175 headers. add ( name: name, value: value)
159176 }
160177
161- let body = await SwiftNIOHTTPClientStreamBridge . convertResponseBody ( from: nioResponse)
178+ let body = await SwiftNIOHTTPClientStreamBridge . convertResponseBody (
179+ from: nioResponse
180+ )
162181
163- let response = HTTPResponse ( headers: headers, body: body, statusCode: statusCode)
182+ let response = HTTPResponse (
183+ headers: headers,
184+ body: body,
185+ statusCode: statusCode
186+ )
164187 logger. debug ( " SwiftNIOHTTPClient( \( httpMethod) \( String ( describing: url) ) ) succeeded " )
165188
166189 return response
167190 } catch {
168191 let urlDescription = String ( describing: url)
169192 let errorDescription = String ( describing: error)
170- logger. error ( " SwiftNIOHTTPClient( \( httpMethod) \( urlDescription) ) failed with error: \( errorDescription) " )
193+ logger. error (
194+ """
195+ SwiftNIOHTTPClient( \( httpMethod) \( urlDescription) ) \
196+ failed with error: \( errorDescription)
197+ """
198+ )
171199 throw error
172200 }
173201 }
@@ -177,7 +205,8 @@ public final class SwiftNIOHTTPClient: SmithyHTTPAPI.HTTPClient {
177205 from request: SmithyHTTPAPI . HTTPRequest
178206 ) async throws -> AsyncHTTPClient . HTTPClientRequest {
179207 var components = URLComponents ( )
180- components. scheme = config. protocolType? . rawValue ?? request. destination. scheme. rawValue
208+ components. scheme = config. protocolType? . rawValue ??
209+ request. destination. scheme. rawValue
181210 components. host = request. endpoint. uri. host
182211 components. port = port ( for: request)
183212 components. percentEncodedPath = request. destination. path
@@ -186,7 +215,9 @@ public final class SwiftNIOHTTPClient: SmithyHTTPAPI.HTTPClient {
186215 URLQueryItem ( name: $0. name, value: $0. value)
187216 }
188217 }
189- guard let url = components. url else { throw SwiftNIOHTTPClientError . incompleteHTTPRequest }
218+ guard let url = components. url else {
219+ throw SwiftNIOHTTPClientError . incompleteHTTPRequest
220+ }
190221
191222 let method = NIOHTTP1 . HTTPMethod ( rawValue: request. method. rawValue)
192223 var nioRequest = AsyncHTTPClient . HTTPClientRequest ( url: url. absoluteString)
0 commit comments