-
Notifications
You must be signed in to change notification settings - Fork 125
Support NIO Transport Services - part 2 #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
a138c04
NIO Transport Services
adam-fowler 33b6de0
Tidying up tests
adam-fowler eb81523
Make sure ENABLE_TS_TESTS toggles TS on and off for all tests
adam-fowler 0b468f2
Don't set TLS hostname for unix connections
adam-fowler b06210f
Removed Handshake promise as it is not used
adam-fowler f40a084
Removed iOS platform requirements, swift-nio-ssl from:2.7.0
adam-fowler 6451389
Moved makeHTTPClientBootstrapBase back to Utils.swift
adam-fowler a7815d1
Updated tests
adam-fowler 8e18b0b
Fixed testProxyTLS()
adam-fowler 61c735e
Got HTTPS tests working, fixed testStressGetHttpsSSLError for TS.
adam-fowler eeea672
TLSEventsHandler wasn't getting added
adam-fowler 4a1ff5d
Renabled ssl in redirect tests
adam-fowler 014cef3
NIOTS set waitForActivity to false
adam-fowler d500a0c
Fixed testAvoidLeakingTLSHandshakeCompletionPromise for TS
adam-fowler 76b3618
Moved my public NIOTSEventLoop to another branch
adam-fowler 8574edd
Simplified requiresSSLHandler check
adam-fowler 9a41fc3
Added TLSConfiguration.getNWProtocolTLSOptions()
adam-fowler 639d0d5
Translate NWError into easier to use structs
adam-fowler 8d43633
Use NIOTSConnectionBootstrap(validatingGroup:)
adam-fowler 299e14c
Re-enabled testStressGetClose()
adam-fowler 69b0e38
Changed NWDNSError into an enum
adam-fowler 0eef5f0
TLSConfiguration convert to NWProtocolTLS.Options changes
adam-fowler f7a3a67
NIOClientTCPBootstrap.makeBootstrap() changes
adam-fowler 131f96a
Clean up suggestions
adam-fowler 72c384b
Run stubs of NIOTS tests on Linux
adam-fowler 9d4e9ef
Formatting changes
adam-fowler 05c0fe1
Re-formatted to make easier to read
adam-fowler 262a6fe
Moved NWTLSError, NWPosixError inside HTTPClient
adam-fowler 038ef0b
Flipped Testing NIOTS switch to be DISABLE_TS_TESTS
adam-fowler 8d92958
swift format fix up
adam-fowler 30d943c
isTestingNIOTS() should return false if you cannot import Network
adam-fowler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
Sources/AsyncHTTPClient/NIOTransportServices/NWErrorHandler.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the AsyncHTTPClient open source project | ||
// | ||
// Copyright (c) 2020 Apple Inc. and the AsyncHTTPClient project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#if canImport(Network) | ||
|
||
import Network | ||
import NIO | ||
import NIOHTTP1 | ||
import NIOTransportServices | ||
|
||
/// Enum containing all the DNS errors | ||
public enum NWDNSError: Error { | ||
case noError | ||
case unknown /* 0xFFFE FFFF */ | ||
case noSuchName | ||
case noMemory | ||
case badParam | ||
case badReference | ||
case badState | ||
case badFlags | ||
case unsupported | ||
case notInitialized | ||
case alreadyRegistered | ||
case nameConflict | ||
case invalid | ||
case firewall | ||
case incompatible /* client library incompatible with daemon */ | ||
case badInterfaceIndex | ||
case refused | ||
case noSuchRecord | ||
case noAuth | ||
case noSuchKey | ||
case NATTraversal | ||
case doubleNAT | ||
case badTime /* Codes up to here existed in Tiger */ | ||
case badSig | ||
case badKey | ||
case transient | ||
case serviceNotRunning /* Background daemon not running */ | ||
case NATPortMappingUnsupported /* NAT doesn't support PCP, NAT-PMP or UPnP */ | ||
case NATPortMappingDisabled /* NAT supports PCP, NAT-PMP or UPnP, but it's disabled by the administrator */ | ||
case noRouter /* No router currently configured (probably no network connectivity) */ | ||
case pollingMode | ||
case timeout | ||
case defunctConnection /* Connection to daemon returned a SO_ISDEFUNCT error result */ | ||
case other(DNSServiceErrorType) | ||
weissi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
extension NWDNSError { | ||
/// Initialize NWDNSError from DNSServiceErrorType | ||
/// - Parameter error: error type | ||
public init(from error: DNSServiceErrorType) { | ||
let errorInt = Int(error) | ||
switch errorInt { | ||
case kDNSServiceErr_NoError: self = .noError | ||
case kDNSServiceErr_Unknown: self = .unknown | ||
case kDNSServiceErr_NoSuchName: self = .noSuchName | ||
case kDNSServiceErr_NoMemory: self = .noMemory | ||
case kDNSServiceErr_BadParam: self = .badParam | ||
case kDNSServiceErr_BadReference: self = .badReference | ||
case kDNSServiceErr_BadState: self = .badState | ||
case kDNSServiceErr_BadFlags: self = .badFlags | ||
case kDNSServiceErr_Unsupported: self = .unsupported | ||
case kDNSServiceErr_NotInitialized: self = .notInitialized | ||
case kDNSServiceErr_AlreadyRegistered: self = .alreadyRegistered | ||
case kDNSServiceErr_NameConflict: self = .nameConflict | ||
case kDNSServiceErr_Invalid: self = .invalid | ||
case kDNSServiceErr_Firewall: self = .firewall | ||
case kDNSServiceErr_Incompatible: self = .incompatible | ||
case kDNSServiceErr_BadInterfaceIndex: self = .badInterfaceIndex | ||
case kDNSServiceErr_Refused: self = .refused | ||
case kDNSServiceErr_NoSuchRecord: self = .noSuchRecord | ||
case kDNSServiceErr_NoAuth: self = .noAuth | ||
case kDNSServiceErr_NoSuchKey: self = .noSuchKey | ||
case kDNSServiceErr_NATTraversal: self = .NATTraversal | ||
case kDNSServiceErr_DoubleNAT: self = .doubleNAT | ||
case kDNSServiceErr_BadTime: self = .badTime | ||
case kDNSServiceErr_BadSig: self = .badSig | ||
case kDNSServiceErr_BadKey: self = .badKey | ||
case kDNSServiceErr_Transient: self = .transient | ||
case kDNSServiceErr_ServiceNotRunning: self = .serviceNotRunning | ||
case kDNSServiceErr_NATPortMappingUnsupported: self = .NATPortMappingUnsupported | ||
case kDNSServiceErr_NATPortMappingDisabled: self = .NATPortMappingDisabled | ||
case kDNSServiceErr_NoRouter: self = .noRouter | ||
case kDNSServiceErr_PollingMode: self = .pollingMode | ||
case kDNSServiceErr_Timeout: self = .timeout | ||
case kDNSServiceErr_DefunctConnection: self = .defunctConnection | ||
default: | ||
self = .other(error) | ||
} | ||
} | ||
} | ||
|
||
public struct NWPOSIXError: Error { | ||
/// POSIX error code (enum) | ||
public let errorCode: POSIXErrorCode | ||
|
||
/// actual reason, in human readable form | ||
private let reason: String | ||
|
||
/// Initialise a NWPOSIXError | ||
/// - Parameters: | ||
/// - errorType: posix error type | ||
/// - reason: String describing reason for error | ||
public init(_ errorCode: POSIXErrorCode, reason: String) { | ||
self.errorCode = errorCode | ||
self.reason = reason | ||
} | ||
} | ||
|
||
extension NWPOSIXError: CustomStringConvertible { | ||
public var description: String { return self.reason } | ||
} | ||
|
||
public struct NWTLSError: Error { | ||
/// TLS error status. List of TLS errors can be found in <Security/SecureTransport.h> | ||
public let status: OSStatus | ||
|
||
/// actual reason, in human readable form | ||
private let reason: String | ||
|
||
/// initialise a NWTLSError | ||
/// - Parameters: | ||
/// - status: TLS status | ||
/// - reason: String describing reason for error | ||
public init(_ status: OSStatus, reason: String) { | ||
self.status = status | ||
self.reason = reason | ||
} | ||
} | ||
|
||
extension NWTLSError: CustomStringConvertible { | ||
public var description: String { return self.reason } | ||
} | ||
|
||
@available(macOS 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) | ||
class NWErrorHandler: ChannelInboundHandler { | ||
typealias InboundIn = HTTPClientResponsePart | ||
|
||
func errorCaught(context: ChannelHandlerContext, error: Error) { | ||
context.fireErrorCaught(NWErrorHandler.translateError(error)) | ||
} | ||
|
||
static func translateError(_ error: Error) -> Error { | ||
if let error = error as? NWError { | ||
switch error { | ||
case .dns(let errorType): | ||
return NWDNSError(from: errorType) | ||
case .tls(let status): | ||
return NWTLSError(status, reason: error.localizedDescription) | ||
case .posix(let errorCode): | ||
return NWPOSIXError(errorCode, reason: error.localizedDescription) | ||
default: | ||
return error | ||
} | ||
} | ||
return error | ||
} | ||
} | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.