Skip to content

Commit ce89513

Browse files
committed
swift-format and remove hacky platform setting
1 parent 96cb4c5 commit ce89513

File tree

10 files changed

+72
-49
lines changed

10 files changed

+72
-49
lines changed

Package.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ let strictConcurrencySettings: [SwiftSetting] = {
3535

3636
let package = Package(
3737
name: "async-http-client",
38-
platforms: [ // FIXME: must remove this
39-
.macOS("10.15")
40-
],
4138
products: [
4239
.library(name: "AsyncHTTPClient", targets: ["AsyncHTTPClient"])
4340
],
@@ -82,7 +79,11 @@ let package = Package(
8279
.product(name: "Atomics", package: "swift-atomics"),
8380
.product(name: "Algorithms", package: "swift-algorithms"),
8481
// Observability support
85-
.product(name: "Tracing", package: "swift-distributed-tracing", condition: .when(traits: ["TracingSupport"])),
82+
.product(
83+
name: "Tracing",
84+
package: "swift-distributed-tracing",
85+
condition: .when(traits: ["TracingSupport"])
86+
),
8687
],
8788
swiftSettings: strictConcurrencySettings
8889
),

[email protected]

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ let strictConcurrencySettings: [SwiftSetting] = {
3535

3636
let package = Package(
3737
name: "async-http-client",
38-
platforms: [ // FIXME: must remove this
39-
.macOS("10.15")
40-
],
4138
products: [
4239
.library(name: "AsyncHTTPClient", targets: ["AsyncHTTPClient"])
4340
],
@@ -82,8 +79,16 @@ let package = Package(
8279
.product(name: "Atomics", package: "swift-atomics"),
8380
.product(name: "Algorithms", package: "swift-algorithms"),
8481
// Observability support
85-
.product(name: "Tracing", package: "swift-distributed-tracing", condition: .when(traits: ["TracingSupport"])),
86-
.product(name: "InMemoryTracing", package: "swift-distributed-tracing", condition: .when(traits: ["TracingSupport"])),
82+
.product(
83+
name: "Tracing",
84+
package: "swift-distributed-tracing",
85+
condition: .when(traits: ["TracingSupport"])
86+
),
87+
.product(
88+
name: "InMemoryTracing",
89+
package: "swift-distributed-tracing",
90+
condition: .when(traits: ["TracingSupport"])
91+
),
8792
],
8893
swiftSettings: strictConcurrencySettings
8994
),
@@ -104,8 +109,16 @@ let package = Package(
104109
.product(name: "Atomics", package: "swift-atomics"),
105110
.product(name: "Algorithms", package: "swift-algorithms"),
106111
// Observability support
107-
.product(name: "Tracing", package: "swift-distributed-tracing", condition: .when(traits: ["TracingSupport"])),
108-
.product(name: "InMemoryTracing", package: "swift-distributed-tracing", condition: .when(traits: ["TracingSupport"])),
112+
.product(
113+
name: "Tracing",
114+
package: "swift-distributed-tracing",
115+
condition: .when(traits: ["TracingSupport"])
116+
),
117+
.product(
118+
name: "InMemoryTracing",
119+
package: "swift-distributed-tracing",
120+
condition: .when(traits: ["TracingSupport"])
121+
),
109122
],
110123
resources: [
111124
.copy("Resources/self_signed_cert.pem"),

Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+execute.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
import Logging
1616
import NIOCore
1717
import NIOHTTP1
18+
19+
import struct Foundation.URL
20+
1821
#if TracingSupport
1922
import Tracing
2023
#endif
2124

22-
import struct Foundation.URL
23-
2425
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2526
extension HTTPClient {
2627
/// Execute arbitrary HTTP requests.
@@ -58,7 +59,7 @@ extension HTTPClient {
5859
}
5960
}
6061
#endif
61-
62+
6263
return try await doExecute()
6364
}
6465
}

Sources/AsyncHTTPClient/AsyncAwait/Transaction.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import NIOSSL
2020

2121
#if TracingSupport
2222
import Tracing
23-
#endif // TracingSupport
23+
#endif // TracingSupport
2424

2525
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2626
@usableFromInline
@@ -60,7 +60,7 @@ final class Transaction:
6060
self.span = span
6161
self.state = NIOLockedValueBox(StateMachine(responseContinuation))
6262
}
63-
#endif // TracingSupport
63+
#endif // TracingSupport
6464

6565
init(
6666
request: HTTPClientRequest.Prepared,

Sources/AsyncHTTPClient/HTTPClient.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public final class HTTPClient: Sendable {
8181
public var tracer: (any Tracer)? {
8282
configuration.tracing.tracer
8383
}
84-
#endif // TracingSupport
84+
#endif // TracingSupport
8585

8686
public static let loggingDisabled = Logger(label: "AHC-do-not-log", factory: { _ in SwiftLogNoOpLogHandler() })
8787

@@ -684,7 +684,7 @@ public final class HTTPClient: Sendable {
684684
deadline: NIODeadline? = nil,
685685
logger: Logger?
686686
) -> Task<Delegate.Response> {
687-
return self._execute(
687+
self._execute(
688688
request: request,
689689
delegate: delegate,
690690
eventLoop: eventLoopPreference,
@@ -718,7 +718,7 @@ public final class HTTPClient: Sendable {
718718
requestID: globalRequestID.wrappingIncrementThenLoad(ordering: .relaxed)
719719
)
720720

721-
// #if TracingSupport
721+
// #if TracingSupport
722722
// let span: (any Span)? // we may be still executing the same span, e.g. under redirection etc.
723723
// if let activeSpan {
724724
// span = activeSpan
@@ -732,7 +732,7 @@ public final class HTTPClient: Sendable {
732732
// span = nil
733733
// }
734734
// #endif
735-
735+
736736
let taskEL: EventLoop
737737
switch eventLoopPreference.preference {
738738
case .indifferent:
@@ -1086,19 +1086,19 @@ public final class HTTPClient: Sendable {
10861086

10871087
#if TracingSupport
10881088
public struct TracingConfiguration: Sendable {
1089-
1090-
@usableFromInline
1091-
var _tracer: Optional<any Sendable> // erasure trick so we don't have to make Configuration @available
10921089

1093-
/// Tracer that should be used by the HTTPClient.
1094-
///
1090+
@usableFromInline
1091+
var _tracer: Optional<any Sendable> // erasure trick so we don't have to make Configuration @available
1092+
1093+
/// Tracer that should be used by the HTTPClient.
1094+
///
10951095
/// This is selected at configuration creation time, and if no tracer is passed explicitly,
10961096
/// (including `nil` in order to disable traces), the default global bootstrapped tracer will
10971097
/// be stored in this property, and used for all subsequent requests made by this client.
10981098
@inlinable
10991099
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
1100-
public var tracer: (any Tracer)? {
1101-
get {
1100+
public var tracer: (any Tracer)? {
1101+
get {
11021102
guard let _tracer else {
11031103
return nil
11041104
}
@@ -1121,13 +1121,13 @@ public final class HTTPClient: Sendable {
11211121

11221122
/// Span attribute keys that the HTTPClient should set automatically.
11231123
/// This struct allows the configuration of the attribute names (keys) which will be used for the apropriate values.
1124-
public struct AttributeKeys: Sendable {
1124+
public struct AttributeKeys: Sendable {
11251125
public var requestMethod: String = "http.request.method"
11261126
public var requestBodySize: String = "http.request.body.size"
11271127

11281128
public var responseBodySize: String = "http.response.size"
11291129
public var responseStatusCode: String = "http.status_code"
1130-
1130+
11311131
public var httpFlavor: String = "http.flavor"
11321132

11331133
public init() {}

Sources/AsyncHTTPClient/HTTPHandler.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,9 +927,9 @@ extension HTTPClient {
927927
public let eventLoop: EventLoop
928928
/// The `Logger` used by the `Task` for logging.
929929
public let logger: Logger // We are okay to store the logger here because a Task is for only one request.
930-
930+
931931
#if TracingSupport
932-
public let tracer: (any Tracer)? // We are okay to store the tracer here because a Task is for only one request.
932+
public let tracer: (any Tracer)? // Ok to store the tracer here because a Task is for only one request.
933933
#endif
934934

935935
let promise: EventLoopPromise<Response>
@@ -986,7 +986,12 @@ extension HTTPClient {
986986
}
987987

988988
#if TracingSupport
989-
init(eventLoop: EventLoop, logger: Logger, tracer: (any Tracer)?, makeOrGetFileIOThreadPool: @escaping @Sendable () -> NIOThreadPool) {
989+
init(
990+
eventLoop: EventLoop,
991+
logger: Logger,
992+
tracer: (any Tracer)?,
993+
makeOrGetFileIOThreadPool: @escaping @Sendable () -> NIOThreadPool
994+
) {
990995
self.eventLoop = eventLoop
991996
self.promise = eventLoop.makePromise()
992997
self.logger = logger

Sources/AsyncHTTPClient/RequestBag.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ final class RequestBag<Delegate: HTTPClientResponseDelegate & Sendable>: Sendabl
5454
var consumeBodyPartStackDepth: Int
5555
// if a redirect occurs, we store the task for it so we can propagate cancellation
5656
var redirectTask: HTTPClient.Task<Delegate.Response>? = nil
57-
58-
#if TracingSupport
57+
58+
#if TracingSupport
5959
// The current span, representing the entire request/response made by an execute call.
6060
var activeSpan: (any Span)? = nil
61-
#endif // TracingSupport
61+
#endif // TracingSupport
6262
}
6363

6464
private let loopBoundState: NIOLoopBoundBox<LoopBoundState>

Sources/AsyncHTTPClient/TracingSupport.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ import Tracing
2525
#if TracingSupport
2626
struct HTTPHeadersInjector: Injector, @unchecked Sendable {
2727
static let shared: HTTPHeadersInjector = HTTPHeadersInjector()
28-
28+
2929
private init() {}
3030

3131
func inject(_ value: String, forKey name: String, into headers: inout HTTPHeaders) {
3232
headers.add(name: name, value: value)
3333
}
3434
}
35-
#endif // TracingSupport
35+
#endif // TracingSupport
3636

3737
#if TracingSupport
3838
typealias HTTPClientTracingSupportTracerType = any Tracer
@@ -52,12 +52,12 @@ protocol _TracingSupportOperations {
5252
mutating func failRequestSpan(error: any Error)
5353

5454
/// Ends the active overall span upon receipt of the response head.
55-
///
55+
///
5656
/// If the status code is in error range, this will automatically fail the span.
5757
mutating func endRequestSpan(response: HTTPResponseHead)
5858
}
5959

60-
extension RequestBag.LoopBoundState: _TracingSupportOperations { }
60+
extension RequestBag.LoopBoundState: _TracingSupportOperations {}
6161

6262
#if !TracingSupport
6363
/// Operations used to start/end spans at apropriate times from the Request lifecycle.
@@ -66,15 +66,15 @@ extension RequestBag.LoopBoundState {
6666

6767
@inlinable
6868
mutating func startRequestSpan(tracer: TracerType?) {}
69-
69+
7070
@inlinable
7171
mutating func failRequestSpan(error: any Error) {}
7272

7373
@inlinable
7474
mutating func endRequestSpan(response: HTTPResponseHead) {}
7575
}
7676

77-
#else // TracingSupport
77+
#else // TracingSupport
7878

7979
extension RequestBag.LoopBoundState {
8080
typealias TracerType = Tracer
@@ -84,13 +84,16 @@ extension RequestBag.LoopBoundState {
8484
return
8585
}
8686

87-
assert(self.activeSpan == nil, "Unexpected active span when starting new request span! Was: \(String(describing: self.activeSpan))")
87+
assert(
88+
self.activeSpan == nil,
89+
"Unexpected active span when starting new request span! Was: \(String(describing: self.activeSpan))"
90+
)
8891
self.activeSpan = tracer.startSpan("\(request.method)")
8992
self.activeSpan?.attributes["loc"] = "\(#fileID):\(#line)"
9093
}
9194

9295
// TODO: should be able to record the reason for the failure, e.g. timeout, cancellation etc.
93-
mutating func failRequestSpan(error: any Error) {
96+
mutating func failRequestSpan(error: any Error) {
9497
guard let span = activeSpan else {
9598
return
9699
}
@@ -114,4 +117,4 @@ extension RequestBag.LoopBoundState {
114117
}
115118
}
116119

117-
#endif // TracingSupport
120+
#endif // TracingSupport

Tests/AsyncHTTPClientTests/HTTPClientBase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class XCTestCaseHTTPClientTestsBaseClass: XCTestCase {
6262
)
6363
backgroundLogger.logLevel = .trace
6464
var configuration = HTTPClient.Configuration().enableFastFailureModeForTesting()
65-
65+
6666
self.defaultClient = HTTPClient(
6767
eventLoopGroupProvider: .shared(self.clientGroup),
6868
configuration: configuration,

Tests/AsyncHTTPClientTests/HTTPClientTracingTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#if TracingSupport
15+
#if TracingSupport
1616

1717
@_spi(Tracing) import AsyncHTTPClient // NOT @testable - tests that need @testable go into HTTPClientInternalTests.swift
1818
import Atomics
@@ -36,7 +36,7 @@ import Network
3636
import Tracing
3737
import InMemoryTracing
3838

39-
fileprivate func makeTracedHTTPClient(tracer: InMemoryTracer) -> HTTPClient {
39+
private func makeTracedHTTPClient(tracer: InMemoryTracer) -> HTTPClient {
4040
var config = HTTPClient.Configuration()
4141
config.httpVersion = .automatic
4242
config.tracing.tracer = tracer
@@ -80,7 +80,7 @@ final class HTTPClientTracingTests: XCTestCaseHTTPClientTestsBaseClass {
8080

8181
XCTAssertEqual(span.operationName, "GET")
8282
}
83-
83+
8484
func testTrace_post_sync() throws {
8585
let url = self.defaultHTTPBinURLPrefix + "echo-method"
8686
let _ = try client.post(url: url).wait()
@@ -107,4 +107,4 @@ final class HTTPClientTracingTests: XCTestCaseHTTPClientTestsBaseClass {
107107
}
108108
}
109109

110-
#endif
110+
#endif

0 commit comments

Comments
 (0)