Skip to content

Commit 2ec8ae2

Browse files
committed
Fix SIL on linux Docker
1 parent e7f38fe commit 2ec8ae2

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

FlyingFox/Sources/HTTPServer+Configuration.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,23 @@ public extension HTTPServer {
5454
}
5555
}
5656
}
57+
58+
59+
extension HTTPServer.Configuration {
60+
61+
init(port: UInt16,
62+
timeout: TimeInterval = 15,
63+
logger: any Logging = HTTPServer.defaultLogger()
64+
) {
65+
#if canImport(WinSDK)
66+
let address = sockaddr_in.inet(port: port)
67+
#else
68+
let address = sockaddr_in6.inet6(port: port)
69+
#endif
70+
self.init(
71+
address: address,
72+
timeout: timeout,
73+
logger: logger
74+
)
75+
}
76+
}

FlyingFox/Sources/HTTPServer.swift

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ public final actor HTTPServer {
4040
private let config: Configuration
4141
private var handlers: RoutedHTTPHandler
4242

43-
public init(config: Configuration, handler: (any HTTPHandler)) {
43+
init(config: Configuration, handler: RoutedHTTPHandler) {
4444
self.config = config
4545
self.handlers = Self.makeRootHandler(to: handler)
4646
}
4747

48+
public init(config: Configuration, handler: (any HTTPHandler)? = nil) {
49+
self.init(config: config, handler: HTTPServer.makeRootHandler(to: handler))
50+
}
51+
4852
public init(address: some SocketAddress,
4953
timeout: TimeInterval = 15,
5054
pool: some AsyncSocketPool = defaultPool(),
@@ -255,6 +259,12 @@ public final actor HTTPServer {
255259
return root
256260
}
257261

262+
private static func makeRootHandler(to closure: @Sendable @escaping (HTTPRequest) async throws -> HTTPResponse) -> RoutedHTTPHandler {
263+
var root = RoutedHTTPHandler()
264+
root.appendRoute("*", to: ClosureHTTPHandler(closure))
265+
return root
266+
}
267+
258268
public static func defaultPool(logger: some Logging = .disabled) -> some AsyncSocketPool {
259269
#if canImport(Darwin)
260270
return .kQueue(logger: logger)
@@ -270,31 +280,26 @@ public extension HTTPServer {
270280

271281
init(port: UInt16,
272282
timeout: TimeInterval = 15,
273-
pool: some AsyncSocketPool = defaultPool(),
274283
logger: any Logging = defaultLogger(),
275284
handler: (any HTTPHandler)? = nil) {
276-
#if canImport(WinSDK)
277-
let address = sockaddr_in.inet(port: port)
278-
#else
279-
let address = sockaddr_in6.inet6(port: port)
280-
#endif
281-
self.init(address: address,
282-
timeout: timeout,
283-
pool: pool,
284-
logger: logger,
285-
handler: handler)
285+
let config = Configuration(
286+
port: port,
287+
timeout: timeout,
288+
logger: logger
289+
)
290+
self.init(config: config, handler: handler)
286291
}
287292

288293
init(port: UInt16,
289294
timeout: TimeInterval = 15,
290-
pool: some AsyncSocketPool = defaultPool(),
291295
logger: any Logging = defaultLogger(),
292296
handler: @Sendable @escaping (HTTPRequest) async throws -> HTTPResponse) {
293-
self.init(port: port,
294-
timeout: timeout,
295-
pool: pool,
296-
logger: logger,
297-
handler: ClosureHTTPHandler(handler))
297+
let config = Configuration(
298+
port: port,
299+
timeout: timeout,
300+
logger: logger
301+
)
302+
self.init(config: config, handler: Self.makeRootHandler(to: handler))
298303
}
299304
}
300305

0 commit comments

Comments
 (0)