This repository was archived by the owner on Apr 7, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathHTTPScheme.swift
More file actions
43 lines (37 loc) · 1.65 KB
/
HTTPScheme.swift
File metadata and controls
43 lines (37 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/// Specifies an HTTP transport-layer scheme.
public struct HTTPScheme {
/// Plaintext data over TCP. Uses port `80` by default.
public static var http: HTTPScheme {
return .init(80) { .done(on: $0.eventLoop) }
}
/// Enables TLS (SSL). Uses port `443` by default.
public static var https: HTTPScheme {
return .init(443) { channel in
return Future.flatMap(on: channel.eventLoop) {
#if os(Linux)
let tlsConfiguration = TLSConfiguration.forClient(certificateVerification: .none)
let sslContext = try SSLContext(configuration: tlsConfiguration)
let tlsHandler = try OpenSSLClientHandler(context: sslContext)
return channel.pipeline.add(handler: tlsHandler)
#else
#warning("Add support for Network.framework TLS")
return .done(on: channel.eventLoop)
#endif
}
}
}
/// See `ws`.
public static let ws: HTTPScheme = .http
/// See `https`.
public static let wss: HTTPScheme = .https
/// The default port to use for this scheme if no override is provided.
public let defaultPort: Int
/// Internal callback for configuring a client channel.
/// This should be expanded with server support at some point.
internal let configureChannel: (Channel) -> Future<Void>
/// Internal initializer, end users will take advantage of pre-defined static variables.
internal init(_ defaultPort: Int, configureChannel: @escaping (Channel) -> Future<Void>) {
self.defaultPort = defaultPort
self.configureChannel = configureChannel
}
}