From 0026463ec4457b19d3c417146e6f5032abcf9ad6 Mon Sep 17 00:00:00 2001 From: Artem Redkin Date: Tue, 27 Aug 2019 11:47:56 +0100 Subject: [PATCH 1/2] nest timeout configuration type inside configuration --- Sources/AsyncHTTPClient/HTTPClient.swift | 36 +++++++++---------- .../HTTPClientTests.swift | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Sources/AsyncHTTPClient/HTTPClient.swift b/Sources/AsyncHTTPClient/HTTPClient.swift index 55db26ce2..76d2e9b11 100644 --- a/Sources/AsyncHTTPClient/HTTPClient.swift +++ b/Sources/AsyncHTTPClient/HTTPClient.swift @@ -290,6 +290,24 @@ public class HTTPClient { /// `HTTPClient` configuration. public struct Configuration { + /// Timeout configuration + public struct Timeout { + /// Specifies connect timeout. + public var connect: TimeAmount? + /// Specifies read timeout. + public var read: TimeAmount? + + /// Create timeout. + /// + /// - parameters: + /// - connect: `connect` timeout. + /// - read: `read` timeout. + public init(connect: TimeAmount? = nil, read: TimeAmount? = nil) { + self.connect = connect + self.read = read + } + } + /// TLS configuration, defaults to `TLSConfiguration.forClient()`. public var tlsConfiguration: TLSConfiguration? /// Enables following 3xx redirects automatically, defaults to `false`. @@ -365,24 +383,6 @@ public class HTTPClient { return EventLoopPreference(.prefers(eventLoop)) } } - - /// Timeout configuration - public struct Timeout { - /// Specifies connect timeout. - public var connect: TimeAmount? - /// Specifies read timeout. - public var read: TimeAmount? - - /// Create timeout. - /// - /// - parameters: - /// - connect: `connect` timeout. - /// - read: `read` timeout. - public init(connect: TimeAmount? = nil, read: TimeAmount? = nil) { - self.connect = connect - self.read = read - } - } } private extension ChannelPipeline { diff --git a/Tests/AsyncHTTPClientTests/HTTPClientTests.swift b/Tests/AsyncHTTPClientTests/HTTPClientTests.swift index 70a776c4d..c3e8bf105 100644 --- a/Tests/AsyncHTTPClientTests/HTTPClientTests.swift +++ b/Tests/AsyncHTTPClientTests/HTTPClientTests.swift @@ -239,7 +239,7 @@ class HTTPClientTests: XCTestCase { func testReadTimeout() throws { let httpBin = HttpBin() - let httpClient = HTTPClient(eventLoopGroupProvider: .createNew, configuration: HTTPClient.Configuration(timeout: HTTPClient.Timeout(read: .milliseconds(150)))) + let httpClient = HTTPClient(eventLoopGroupProvider: .createNew, configuration: HTTPClient.Configuration(timeout: HTTPClient.Configuration.Timeout(read: .milliseconds(150)))) defer { try! httpClient.syncShutdown() From 395ef5d515e765c86581f28568794caabf743d45 Mon Sep 17 00:00:00 2001 From: Artem Redkin Date: Tue, 27 Aug 2019 11:56:12 +0100 Subject: [PATCH 2/2] move timeout to an extension --- Sources/AsyncHTTPClient/HTTPClient.swift | 38 +++++++++++++----------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Sources/AsyncHTTPClient/HTTPClient.swift b/Sources/AsyncHTTPClient/HTTPClient.swift index b0bc6f3b2..57807f1ec 100644 --- a/Sources/AsyncHTTPClient/HTTPClient.swift +++ b/Sources/AsyncHTTPClient/HTTPClient.swift @@ -290,24 +290,6 @@ public class HTTPClient { /// `HTTPClient` configuration. public struct Configuration { - /// Timeout configuration - public struct Timeout { - /// Specifies connect timeout. - public var connect: TimeAmount? - /// Specifies read timeout. - public var read: TimeAmount? - - /// Create timeout. - /// - /// - parameters: - /// - connect: `connect` timeout. - /// - read: `read` timeout. - public init(connect: TimeAmount? = nil, read: TimeAmount? = nil) { - self.connect = connect - self.read = read - } - } - /// TLS configuration, defaults to `TLSConfiguration.forClient()`. public var tlsConfiguration: TLSConfiguration? /// Enables following 3xx redirects automatically, defaults to `false`. @@ -385,6 +367,26 @@ public class HTTPClient { } } +extension HTTPClient.Configuration { + /// Timeout configuration + public struct Timeout { + /// Specifies connect timeout. + public var connect: TimeAmount? + /// Specifies read timeout. + public var read: TimeAmount? + + /// Create timeout. + /// + /// - parameters: + /// - connect: `connect` timeout. + /// - read: `read` timeout. + public init(connect: TimeAmount? = nil, read: TimeAmount? = nil) { + self.connect = connect + self.read = read + } + } +} + private extension ChannelPipeline { func addProxyHandler(for request: HTTPClient.Request, decoder: ByteToMessageHandler, encoder: HTTPRequestEncoder, tlsConfiguration: TLSConfiguration?) -> EventLoopFuture { let handler = HTTPClientProxyHandler(host: request.host, port: request.port, onConnect: { channel in