Skip to content

Commit a2da342

Browse files
committed
ProxyConnectHandler reduce memory layout size
1 parent f9c784c commit a2da342

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

Sources/NIOExtras/HTTP1ProxyConnectHandler.swift

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,21 @@ public final class NIOHTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableC
210210
public struct Error: Swift.Error, Equatable {
211211
fileprivate enum Storage: Equatable, Hashable {
212212
case proxyAuthenticationRequired
213-
case invalidProxyResponseHead(head: HTTPResponseHead)
213+
indirect case invalidProxyResponseHead(head: HTTPResponseHead)
214214
case invalidProxyResponse
215215
case remoteConnectionClosed
216216
case httpProxyHandshakeTimeout
217217
case noResult
218218

219+
// compare only the kind of error, not the associated response head
219220
@inlinable
220221
static func == (lhs: Self, rhs: Self) -> Bool {
221-
return Kind(from: lhs) == Kind(from: rhs)
222+
Kind(lhs) == Kind(rhs)
222223
}
223224

224225
@inlinable
225226
public func hash(into hasher: inout Hasher) {
226-
hasher.combine(Kind(from: self))
227+
hasher.combine(Kind(self))
227228
}
228229
}
229230

@@ -235,7 +236,7 @@ public final class NIOHTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableC
235236
case httpProxyHandshakeTimeout
236237
case noResult
237238

238-
init(from storage: Storage) {
239+
init(_ storage: Storage) {
239240
switch storage {
240241
case .proxyAuthenticationRequired:
241242
self = .proxyAuthenticationRequired
@@ -253,15 +254,26 @@ public final class NIOHTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableC
253254
}
254255
}
255256

256-
fileprivate let error: Storage
257+
final class Location: Sendable {
258+
public let file: String
259+
public let line: UInt
260+
init(file: String, line: UInt) {
261+
self.file = file
262+
self.line = line
263+
}
264+
}
257265

258-
public var file: String
259-
public var line: Int
266+
fileprivate let error: Storage
267+
let location: Location
260268

261-
fileprivate init(error: Storage, file: String = #file, line: Int = #line) {
269+
fileprivate init(error: Storage, file: String = #file, line: UInt = #line) {
262270
self.error = error
263-
self.file = file
264-
self.line = line
271+
self.location = Location(file: file, line: line)
272+
}
273+
274+
public static func == (lhs: NIOHTTP1ProxyConnectHandler.Error, rhs: NIOHTTP1ProxyConnectHandler.Error) -> Bool {
275+
// ignore *where* the error was thrown
276+
lhs.error == rhs.error
265277
}
266278

267279
/// Proxy response status `407` indicates that authentication is required

Tests/NIOExtrasTests/HTTP1ProxyConnectHandlerTests+XCTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the SwiftNIO open source project
44
//
5-
// Copyright (c) 2022 Apple Inc. and the SwiftNIO project authors
5+
// Copyright (c) 2018-2022 Apple Inc. and the SwiftNIO project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information

0 commit comments

Comments
 (0)