Skip to content

Commit f7a3a67

Browse files
committed
NIOClientTCPBootstrap.makeBootstrap() changes
Removed setting option `waitForActivity` to false If running with a proxy don't setup NIOTSClientTLSProvider While running NIOTS ignore SSL unclean shutdown tests
1 parent 0eef5f0 commit f7a3a67

File tree

3 files changed

+48
-26
lines changed

3 files changed

+48
-26
lines changed

Sources/AsyncHTTPClient/Utils.swift

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ extension ClientBootstrap {
5858
requiresTLS: Bool,
5959
configuration: HTTPClient.Configuration
6060
) throws -> NIOClientTCPBootstrap {
61-
let tlsConfiguration = configuration.tlsConfiguration ?? TLSConfiguration.forClient()
62-
let sslContext = try NIOSSLContext(configuration: tlsConfiguration)
63-
let hostname = (!requiresTLS || host.isIPAddress) ? nil : host
64-
let tlsProvider = try NIOSSLClientTLSProvider<ClientBootstrap>(context: sslContext, serverHostname: hostname)
65-
return NIOClientTCPBootstrap(self, tls: tlsProvider)
61+
// if there is a proxy don't create TLS provider as it will be added at a later point
62+
if configuration.proxy != nil {
63+
return NIOClientTCPBootstrap(self, tls: NIOInsecureNoTLS())
64+
} else {
65+
let tlsConfiguration = configuration.tlsConfiguration ?? TLSConfiguration.forClient()
66+
let sslContext = try NIOSSLContext(configuration: tlsConfiguration)
67+
let hostname = (!requiresTLS || host.isIPAddress) ? nil : host
68+
let tlsProvider = try NIOSSLClientTLSProvider<ClientBootstrap>(context: sslContext, serverHostname: hostname)
69+
return NIOClientTCPBootstrap(self, tls: tlsProvider)
70+
}
6671
}
6772
}
6873

@@ -79,15 +84,11 @@ extension NIOClientTCPBootstrap {
7984
#if canImport(Network)
8085
// if eventLoop is compatible with NIOTransportServices create a NIOTSConnectionBootstrap
8186
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *),
82-
var tsBootstrap = NIOTSConnectionBootstrap(validatingGroup: eventLoop) {
83-
84-
tsBootstrap = tsBootstrap.channelOption(NIOTSChannelOptions.waitForActivity, value: false)
87+
let tsBootstrap = NIOTSConnectionBootstrap(validatingGroup: eventLoop) {
8588
let tlsConfiguration = configuration.tlsConfiguration ?? TLSConfiguration.forClient()
86-
// if we have a proxy and require TLS then use NIOSSL tls support
87-
if configuration.proxy != nil, requiresTLS {
88-
let sslContext = try NIOSSLContext(configuration: tlsConfiguration)
89-
let hostname = (!requiresTLS || host.isIPAddress) ? nil : host
90-
bootstrap = try NIOClientTCPBootstrap(tsBootstrap, tls: NIOSSLClientTLSProvider(context: sslContext, serverHostname: hostname))
89+
// if there is a proxy don't create TLS provider as it will be added at a later point
90+
if configuration.proxy != nil {
91+
bootstrap = NIOClientTCPBootstrap(tsBootstrap, tls: NIOInsecureNoTLS())
9192
} else {
9293
// create NIOClientTCPBootstrap with NIOTS TLS provider
9394
let parameters = tlsConfiguration.getNWProtocolTLSOptions()

Tests/AsyncHTTPClientTests/HTTPClientNIOTSTests.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class HTTPClientNIOTSTests: XCTestCase {
5757
do {
5858
_ = try httpClient.get(url: "http://dnsfail/").wait()
5959
XCTFail("This should have failed")
60-
} catch NWDNSError.noSuchRecord {
60+
} catch ChannelError.connectTimeout {
6161
} catch {
62-
XCTFail("Error should have been NWDSNError.noSuchRecord not \(error)")
62+
XCTFail("Error should have been ChannelError.connectTimeout not \(error)")
6363
}
6464
}
6565

@@ -95,10 +95,9 @@ class HTTPClientNIOTSTests: XCTestCase {
9595
do {
9696
_ = try httpClient.get(url: "https://localhost:\(port)/get").wait()
9797
XCTFail("This should have failed")
98-
} catch let error as NWPOSIXError {
99-
XCTAssertEqual(error.errorCode, .ECONNREFUSED)
98+
} catch ChannelError.connectTimeout {
10099
} catch {
101-
XCTFail("Error should have been NWPOSIXError not \(type(of:error))")
100+
XCTFail("Error should have been ChannelError.connectTimeout not \(type(of:error))")
102101
}
103102
}
104103

Tests/AsyncHTTPClientTests/HTTPClientTests.swift

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,9 @@ class HTTPClientTests: XCTestCase {
471471
}
472472

473473
func testNoContentLengthForSSLUncleanShutdown() throws {
474+
// NIOTS deals with ssl unclean shutdown internally
475+
guard !isTestingNIOTS() else { return }
476+
474477
let httpBin = HttpBinForSSLUncleanShutdown()
475478
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
476479
configuration: HTTPClient.Configuration(certificateVerification: .none))
@@ -488,6 +491,9 @@ class HTTPClientTests: XCTestCase {
488491
}
489492

490493
func testNoContentLengthWithIgnoreErrorForSSLUncleanShutdown() throws {
494+
// NIOTS deals with ssl unclean shutdown internally
495+
guard !isTestingNIOTS() else { return }
496+
491497
let httpBin = HttpBinForSSLUncleanShutdown()
492498
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
493499
configuration: HTTPClient.Configuration(certificateVerification: .none, ignoreUncleanSSLShutdown: true))
@@ -506,6 +512,9 @@ class HTTPClientTests: XCTestCase {
506512
}
507513

508514
func testCorrectContentLengthForSSLUncleanShutdown() throws {
515+
// NIOTS deals with ssl unclean shutdown internally
516+
guard !isTestingNIOTS() else { return }
517+
509518
let httpBin = HttpBinForSSLUncleanShutdown()
510519
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
511520
configuration: HTTPClient.Configuration(certificateVerification: .none))
@@ -524,6 +533,9 @@ class HTTPClientTests: XCTestCase {
524533
}
525534

526535
func testNoContentForSSLUncleanShutdown() throws {
536+
// NIOTS deals with ssl unclean shutdown internally
537+
guard !isTestingNIOTS() else { return }
538+
527539
let httpBin = HttpBinForSSLUncleanShutdown()
528540
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
529541
configuration: HTTPClient.Configuration(certificateVerification: .none))
@@ -540,6 +552,9 @@ class HTTPClientTests: XCTestCase {
540552
}
541553

542554
func testNoResponseForSSLUncleanShutdown() throws {
555+
// NIOTS deals with ssl unclean shutdown internally
556+
guard !isTestingNIOTS() else { return }
557+
543558
let httpBin = HttpBinForSSLUncleanShutdown()
544559
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
545560
configuration: HTTPClient.Configuration(certificateVerification: .none))
@@ -557,6 +572,9 @@ class HTTPClientTests: XCTestCase {
557572
}
558573

559574
func testNoResponseWithIgnoreErrorForSSLUncleanShutdown() throws {
575+
// NIOTS deals with ssl unclean shutdown internally
576+
guard !isTestingNIOTS() else { return }
577+
560578
let httpBin = HttpBinForSSLUncleanShutdown()
561579
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
562580
configuration: HTTPClient.Configuration(certificateVerification: .none, ignoreUncleanSSLShutdown: true))
@@ -574,6 +592,9 @@ class HTTPClientTests: XCTestCase {
574592
}
575593

576594
func testWrongContentLengthForSSLUncleanShutdown() throws {
595+
// NIOTS deals with ssl unclean shutdown internally
596+
guard !isTestingNIOTS() else { return }
597+
577598
let httpBin = HttpBinForSSLUncleanShutdown()
578599
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
579600
configuration: HTTPClient.Configuration(certificateVerification: .none))
@@ -591,6 +612,9 @@ class HTTPClientTests: XCTestCase {
591612
}
592613

593614
func testWrongContentLengthWithIgnoreErrorForSSLUncleanShutdown() throws {
615+
// NIOTS deals with ssl unclean shutdown internally
616+
guard !isTestingNIOTS() else { return }
617+
594618
let httpBin = HttpBinForSSLUncleanShutdown()
595619
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
596620
configuration: HTTPClient.Configuration(certificateVerification: .none, ignoreUncleanSSLShutdown: true))
@@ -1675,18 +1699,16 @@ class HTTPClientTests: XCTestCase {
16751699
}
16761700

16771701
XCTAssertThrowsError(try httpClient.get(url: "http://localhost:\(port)").wait()) { error in
1678-
#if canImport(Network)
16791702
if isTestingNIOTS() {
1680-
guard let ioError = error as? NWPOSIXError, ioError.errorCode == .ECONNREFUSED else {
1703+
guard case ChannelError.connectTimeout = error else {
1704+
XCTFail("Unexpected error: \(error)")
1705+
return
1706+
}
1707+
} else {
1708+
guard error is NIOConnectionError else {
16811709
XCTFail("Unexpected error: \(error)")
16821710
return
16831711
}
1684-
return
1685-
}
1686-
#endif
1687-
guard error is NIOConnectionError else {
1688-
XCTFail("Unexpected error: \(error)")
1689-
return
16901712
}
16911713
}
16921714
}

0 commit comments

Comments
 (0)