Skip to content

Commit 3dc7fdf

Browse files
committed
swiftlint more
1 parent 0e0f62f commit 3dc7fdf

File tree

4 files changed

+92
-29
lines changed

4 files changed

+92
-29
lines changed

Sources/SmithySwiftNIO/SwiftNIOHTTPClient.swift

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
2323
public 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)

Sources/SmithySwiftNIO/SwiftNIOHTTPClientConfiguration+HTTPClientConfiguration.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import NIOCore
1111

1212
extension HTTPClient.Configuration {
1313

14-
static func from(httpClientConfiguration: ClientRuntime.HttpClientConfiguration) -> HTTPClient.Configuration {
14+
static func from(
15+
httpClientConfiguration: ClientRuntime.HttpClientConfiguration
16+
) -> HTTPClient.Configuration {
1517
let connect: TimeAmount? = httpClientConfiguration.connectTimeout != nil
1618
? .seconds(Int64(httpClientConfiguration.connectTimeout!))
1719
: nil
@@ -25,7 +27,8 @@ extension HTTPClient.Configuration {
2527

2628
let pool = HTTPClient.Configuration.ConnectionPool(
2729
idleTimeout: .seconds(60), // default
28-
concurrentHTTP1ConnectionsPerHostSoftLimit: httpClientConfiguration.maxConnections
30+
concurrentHTTP1ConnectionsPerHostSoftLimit:
31+
httpClientConfiguration.maxConnections
2932
)
3033

3134
return .init(

Sources/SmithySwiftNIO/SwiftNIOHTTPClientStreamBridge.swift

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ final class SwiftNIOHTTPClientStreamBridge {
1919
from body: ByteStream,
2020
allocator: ByteBufferAllocator,
2121
chunkSize: Int = CHUNK_SIZE_BYTES
22-
) async throws -> AsyncHTTPClient.HTTPClientRequest.Body {
22+
) async throws
23+
-> AsyncHTTPClient.HTTPClientRequest.Body {
2324
switch body {
2425
case .noStream:
2526
// No body to send
@@ -37,7 +38,11 @@ final class SwiftNIOHTTPClientStreamBridge {
3738

3839
case .stream(let stream):
3940
// Handle streaming request body
40-
return try await convertStreamToRequestBody(stream: stream, allocator: allocator, chunkSize: chunkSize)
41+
return try await convertStreamToRequestBody(
42+
stream: stream,
43+
allocator: allocator,
44+
chunkSize: chunkSize
45+
)
4146
}
4247
}
4348

@@ -51,7 +56,10 @@ final class SwiftNIOHTTPClientStreamBridge {
5156
var iterator = response.body.makeAsyncIterator()
5257
while let buffer = try await iterator.next() {
5358
// Convert ByteBuffer to Data and write to buffered stream
54-
if let bytes = buffer.getBytes(at: buffer.readerIndex, length: buffer.readableBytes) {
59+
if let bytes = buffer.getBytes(
60+
at: buffer.readerIndex,
61+
length: buffer.readableBytes
62+
) {
5563
let data = Data(bytes)
5664
try bufferedStream.write(contentsOf: data)
5765
}
@@ -70,7 +78,11 @@ final class SwiftNIOHTTPClientStreamBridge {
7078
allocator: ByteBufferAllocator,
7179
chunkSize: Int = CHUNK_SIZE_BYTES
7280
) async throws -> AsyncHTTPClient.HTTPClientRequest.Body {
73-
let asyncSequence = StreamToAsyncSequence(stream: stream, allocator: allocator, chunkSize: chunkSize)
81+
let asyncSequence = StreamToAsyncSequence(
82+
stream: stream,
83+
allocator: allocator,
84+
chunkSize: chunkSize
85+
)
7486

7587
// Use known length if available, unless the stream is eligible for chunked streaming.
7688
if let length = stream.length, !stream.isEligibleForChunkedStreaming {
@@ -89,7 +101,11 @@ internal struct StreamToAsyncSequence: AsyncSequence, Sendable {
89101
private let allocator: ByteBufferAllocator
90102
private let chunkSize: Int
91103

92-
init(stream: Smithy.Stream, allocator: ByteBufferAllocator, chunkSize: Int = CHUNK_SIZE_BYTES) {
104+
init(
105+
stream: Smithy.Stream,
106+
allocator: ByteBufferAllocator,
107+
chunkSize: Int = CHUNK_SIZE_BYTES
108+
) {
93109
self.stream = stream
94110
self.allocator = allocator
95111
self.chunkSize = chunkSize

Sources/SmithySwiftNIO/SwiftNIOHTTPClientTLSResolverUtils.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ extension SwiftNIOHTTPClientTLSOptions {
2626

2727
if useProvidedKeystore {
2828
if let pkcs12Path = pkcs12Path, let pkcs12Password = pkcs12Password {
29-
let bundle = try SwiftNIOHTTPClientTLSOptions.loadPKCS12Bundle(from: pkcs12Path, password: pkcs12Password)
29+
let bundle = try SwiftNIOHTTPClientTLSOptions.loadPKCS12Bundle(
30+
from: pkcs12Path,
31+
password: pkcs12Password
32+
)
3033
tlsConfig.certificateChain = bundle.certificateChain.map { .certificate($0) }
3134
tlsConfig.privateKey = .privateKey(bundle.privateKey)
3235
} else if let certificate = certificate, let privateKey = privateKey {
33-
let cert = try SwiftNIOHTTPClientTLSOptions.loadCertificate(from: certificate)
34-
let key = try SwiftNIOHTTPClientTLSOptions.loadPrivateKey(from: privateKey)
36+
let cert = try SwiftNIOHTTPClientTLSOptions.loadCertificate(
37+
from: certificate
38+
)
39+
let key = try SwiftNIOHTTPClientTLSOptions.loadPrivateKey(
40+
from: privateKey
41+
)
3542
tlsConfig.certificateChain = [.certificate(cert)]
3643
tlsConfig.privateKey = .privateKey(key)
3744
}
@@ -61,7 +68,10 @@ extension SwiftNIOHTTPClientTLSOptions {
6168
return try NIOSSLPrivateKey(bytes: Array(fileData), format: .pem)
6269
}
6370

64-
static func loadPKCS12Bundle(from filePath: String, password: String) throws -> NIOSSLPKCS12Bundle {
71+
static func loadPKCS12Bundle(
72+
from filePath: String,
73+
password: String
74+
) throws -> NIOSSLPKCS12Bundle {
6575
do {
6676
return try NIOSSLPKCS12Bundle(file: filePath, passphrase: password.utf8)
6777
} catch {
@@ -79,7 +89,10 @@ public enum SwiftNIOHTTPClientTLSError: Error, LocalizedError {
7989
case .noCertificateFound(let path):
8090
return "No certificate found at path: \(path)"
8191
case .invalidPKCS12(let path, let underlying):
82-
return "Failed to load PKCS#12 file at path: \(path). Error: \(String(describing: underlying))"
92+
return """
93+
Failed to load PKCS#12 file at path: \(path). \
94+
Error: \(String(describing: underlying))
95+
"""
8396
}
8497
}
8598
}

0 commit comments

Comments
 (0)