@@ -113,7 +113,6 @@ public final class NIOHTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableC
113
113
context. leavePipeline ( removalToken: removalToken)
114
114
}
115
115
116
-
117
116
public func handlerAdded( context: ChannelHandlerContext ) {
118
117
if context. channel. isActive {
119
118
self . sendConnect ( context: context)
@@ -139,7 +138,7 @@ public final class NIOHTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableC
139
138
public func channelInactive( context: ChannelHandlerContext ) {
140
139
switch self . state {
141
140
case . initialized:
142
- preconditionFailure ( " How can we receive a channelInactive before a channelActive? " )
141
+ self . failWithError ( Error . channelUnexpectedlyInactive ( ) , context : context , closeConnection : false )
143
142
case . connectSent( let timeout) , . headReceived( let timeout) :
144
143
timeout. cancel ( )
145
144
self . failWithError ( Error . remoteConnectionClosed ( ) , context: context, closeConnection: false )
@@ -276,6 +275,7 @@ public final class NIOHTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableC
276
275
case remoteConnectionClosed
277
276
case httpProxyHandshakeTimeout
278
277
case noResult
278
+ case channelUnexpectedlyInactive
279
279
}
280
280
281
281
final class Storage : Sendable {
@@ -326,6 +326,11 @@ public final class NIOHTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableC
326
326
Error ( error: . noResult, file: file, line: line)
327
327
}
328
328
329
+ /// Handler became unexpectedly inactive before a connection was made
330
+ public static func channelUnexpectedlyInactive( file: String = #file, line: UInt = #line) -> Error {
331
+ Error ( error: . channelUnexpectedlyInactive, file: file, line: line)
332
+ }
333
+
329
334
fileprivate var errorCode : Int {
330
335
switch self . store. details {
331
336
case . proxyAuthenticationRequired:
@@ -340,6 +345,8 @@ public final class NIOHTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableC
340
345
return 4
341
346
case . noResult:
342
347
return 5
348
+ case . channelUnexpectedlyInactive:
349
+ return 6
343
350
}
344
351
}
345
352
}
@@ -379,6 +386,8 @@ extension NIOHTTP1ProxyConnectHandler.Error.Details: CustomStringConvertible {
379
386
return " HTTP Proxy Handshake Timeout "
380
387
case . noResult:
381
388
return " No Result "
389
+ case . channelUnexpectedlyInactive:
390
+ return " Channel Unexpectedly Inactive "
382
391
}
383
392
}
384
393
}
0 commit comments