Skip to content

Commit f9c784c

Browse files
committed
invalidProxyResponseHead equality ignores content, error improvements
1 parent 48b3369 commit f9c784c

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

Sources/NIOExtras/HTTP1ProxyConnectHandler.swift

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public final class NIOHTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableC
5050
/// - deadline: Deadline for the CONNECT request
5151
/// - promise: Promise with which the result of the connect operation is communicated
5252
public init(targetHost: String,
53-
targetPort: Int,
54-
headers: HTTPHeaders,
55-
deadline: NIODeadline,
56-
promise: EventLoopPromise<Void>) {
53+
targetPort: Int,
54+
headers: HTTPHeaders,
55+
deadline: NIODeadline,
56+
promise: EventLoopPromise<Void>) {
5757
self.targetHost = targetHost
5858
self.targetPort = targetPort
5959
self.headers = headers
@@ -208,16 +208,61 @@ public final class NIOHTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableC
208208

209209
/// Error types for ``HTTP1ProxyConnectHandler``
210210
public struct Error: Swift.Error, Equatable {
211-
212-
fileprivate enum ErrorEnum: Equatable {
211+
fileprivate enum Storage: Equatable, Hashable {
213212
case proxyAuthenticationRequired
214213
case invalidProxyResponseHead(head: HTTPResponseHead)
215214
case invalidProxyResponse
216215
case remoteConnectionClosed
217216
case httpProxyHandshakeTimeout
218217
case noResult
218+
219+
@inlinable
220+
static func == (lhs: Self, rhs: Self) -> Bool {
221+
return Kind(from: lhs) == Kind(from: rhs)
222+
}
223+
224+
@inlinable
225+
public func hash(into hasher: inout Hasher) {
226+
hasher.combine(Kind(from: self))
227+
}
228+
}
229+
230+
fileprivate enum Kind: Equatable, Hashable {
231+
case proxyAuthenticationRequired
232+
case invalidProxyResponseHead
233+
case invalidProxyResponse
234+
case remoteConnectionClosed
235+
case httpProxyHandshakeTimeout
236+
case noResult
237+
238+
init(from storage: Storage) {
239+
switch storage {
240+
case .proxyAuthenticationRequired:
241+
self = .proxyAuthenticationRequired
242+
case .invalidProxyResponseHead:
243+
self = .invalidProxyResponseHead
244+
case .invalidProxyResponse:
245+
self = .invalidProxyResponse
246+
case .remoteConnectionClosed:
247+
self = .remoteConnectionClosed
248+
case .httpProxyHandshakeTimeout:
249+
self = .httpProxyHandshakeTimeout
250+
case .noResult:
251+
self = .noResult
252+
}
253+
}
254+
}
255+
256+
fileprivate let error: Storage
257+
258+
public var file: String
259+
public var line: Int
260+
261+
fileprivate init(error: Storage, file: String = #file, line: Int = #line) {
262+
self.error = error
263+
self.file = file
264+
self.line = line
219265
}
220-
fileprivate let error: ErrorEnum
221266

222267
/// Proxy response status `407` indicates that authentication is required
223268
public static let proxyAuthenticationRequired = Error(error: .proxyAuthenticationRequired)

0 commit comments

Comments
 (0)