Skip to content

Commit 6ff6294

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 94803b1 commit 6ff6294

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
@@ -459,6 +459,9 @@ class HTTPClientTests: XCTestCase {
459459
}
460460

461461
func testNoContentLengthForSSLUncleanShutdown() throws {
462+
// NIOTS deals with ssl unclean shutdown internally
463+
guard !isTestingNIOTS() else { return }
464+
462465
let httpBin = HttpBinForSSLUncleanShutdown()
463466
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
464467
configuration: HTTPClient.Configuration(certificateVerification: .none))
@@ -476,6 +479,9 @@ class HTTPClientTests: XCTestCase {
476479
}
477480

478481
func testNoContentLengthWithIgnoreErrorForSSLUncleanShutdown() throws {
482+
// NIOTS deals with ssl unclean shutdown internally
483+
guard !isTestingNIOTS() else { return }
484+
479485
let httpBin = HttpBinForSSLUncleanShutdown()
480486
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
481487
configuration: HTTPClient.Configuration(certificateVerification: .none, ignoreUncleanSSLShutdown: true))
@@ -494,6 +500,9 @@ class HTTPClientTests: XCTestCase {
494500
}
495501

496502
func testCorrectContentLengthForSSLUncleanShutdown() throws {
503+
// NIOTS deals with ssl unclean shutdown internally
504+
guard !isTestingNIOTS() else { return }
505+
497506
let httpBin = HttpBinForSSLUncleanShutdown()
498507
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
499508
configuration: HTTPClient.Configuration(certificateVerification: .none))
@@ -512,6 +521,9 @@ class HTTPClientTests: XCTestCase {
512521
}
513522

514523
func testNoContentForSSLUncleanShutdown() throws {
524+
// NIOTS deals with ssl unclean shutdown internally
525+
guard !isTestingNIOTS() else { return }
526+
515527
let httpBin = HttpBinForSSLUncleanShutdown()
516528
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
517529
configuration: HTTPClient.Configuration(certificateVerification: .none))
@@ -528,6 +540,9 @@ class HTTPClientTests: XCTestCase {
528540
}
529541

530542
func testNoResponseForSSLUncleanShutdown() throws {
543+
// NIOTS deals with ssl unclean shutdown internally
544+
guard !isTestingNIOTS() else { return }
545+
531546
let httpBin = HttpBinForSSLUncleanShutdown()
532547
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
533548
configuration: HTTPClient.Configuration(certificateVerification: .none))
@@ -545,6 +560,9 @@ class HTTPClientTests: XCTestCase {
545560
}
546561

547562
func testNoResponseWithIgnoreErrorForSSLUncleanShutdown() throws {
563+
// NIOTS deals with ssl unclean shutdown internally
564+
guard !isTestingNIOTS() else { return }
565+
548566
let httpBin = HttpBinForSSLUncleanShutdown()
549567
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
550568
configuration: HTTPClient.Configuration(certificateVerification: .none, ignoreUncleanSSLShutdown: true))
@@ -562,6 +580,9 @@ class HTTPClientTests: XCTestCase {
562580
}
563581

564582
func testWrongContentLengthForSSLUncleanShutdown() throws {
583+
// NIOTS deals with ssl unclean shutdown internally
584+
guard !isTestingNIOTS() else { return }
585+
565586
let httpBin = HttpBinForSSLUncleanShutdown()
566587
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
567588
configuration: HTTPClient.Configuration(certificateVerification: .none))
@@ -579,6 +600,9 @@ class HTTPClientTests: XCTestCase {
579600
}
580601

581602
func testWrongContentLengthWithIgnoreErrorForSSLUncleanShutdown() throws {
603+
// NIOTS deals with ssl unclean shutdown internally
604+
guard !isTestingNIOTS() else { return }
605+
582606
let httpBin = HttpBinForSSLUncleanShutdown()
583607
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
584608
configuration: HTTPClient.Configuration(certificateVerification: .none, ignoreUncleanSSLShutdown: true))
@@ -1663,18 +1687,16 @@ class HTTPClientTests: XCTestCase {
16631687
}
16641688

16651689
XCTAssertThrowsError(try httpClient.get(url: "http://localhost:\(port)").wait()) { error in
1666-
#if canImport(Network)
16671690
if isTestingNIOTS() {
1668-
guard let ioError = error as? NWPOSIXError, ioError.errorCode == .ECONNREFUSED else {
1691+
guard case ChannelError.connectTimeout = error else {
1692+
XCTFail("Unexpected error: \(error)")
1693+
return
1694+
}
1695+
} else {
1696+
guard error is NIOConnectionError else {
16691697
XCTFail("Unexpected error: \(error)")
16701698
return
16711699
}
1672-
return
1673-
}
1674-
#endif
1675-
guard error is NIOConnectionError else {
1676-
XCTFail("Unexpected error: \(error)")
1677-
return
16781700
}
16791701
}
16801702
}

0 commit comments

Comments
 (0)