@@ -82,6 +82,9 @@ class HTTPRequestStateMachineTests: XCTestCase {
82
82
}
83
83
84
84
XCTAssertEqual ( error as? HTTPClientError , . bodyLengthMismatch)
85
+
86
+ // if another error happens the new one is ignored
87
+ XCTAssertEqual ( state. errorHappened ( HTTPClientError . remoteConnectionClosed) , . wait)
85
88
}
86
89
87
90
func testPOSTContentLengthIsTooShort( ) {
@@ -521,6 +524,28 @@ class HTTPRequestStateMachineTests: XCTestCase {
521
524
XCTAssertEqual ( state. channelRead ( . end( nil ) ) , . wait)
522
525
XCTAssertEqual ( state. channelInactive ( ) , . wait)
523
526
}
527
+
528
+ func testNIOSSLErrorUncleanShutdownShouldBeTreatedAsRemoteConnectionCloseWhileInWaitingForHeadState( ) {
529
+ var state = HTTPRequestStateMachine ( isChannelWritable: true )
530
+ let requestHead = HTTPRequestHead ( version: . http1_1, method: . GET, uri: " / " )
531
+ let metadata = RequestFramingMetadata ( connectionClose: false , body: . fixedSize( 0 ) )
532
+ XCTAssertEqual ( state. startRequest ( head: requestHead, metadata: metadata) , . sendRequestHead( requestHead, startBody: false ) )
533
+
534
+ XCTAssertEqual ( state. errorHappened ( NIOSSLError . uncleanShutdown) , . wait)
535
+ XCTAssertEqual ( state. channelInactive ( ) , . failRequest( HTTPClientError . remoteConnectionClosed, . none) )
536
+ }
537
+
538
+
539
+ func testArbitraryErrorShouldBeTreatedAsARequestFailureWhileInWaitingForHeadState( ) {
540
+ struct ArbitraryError : Error { }
541
+ var state = HTTPRequestStateMachine ( isChannelWritable: true )
542
+ let requestHead = HTTPRequestHead ( version: . http1_1, method: . GET, uri: " / " )
543
+ let metadata = RequestFramingMetadata ( connectionClose: false , body: . fixedSize( 0 ) )
544
+ XCTAssertEqual ( state. startRequest ( head: requestHead, metadata: metadata) , . sendRequestHead( requestHead, startBody: false ) )
545
+
546
+ XCTAssertEqual ( state. errorHappened ( ArbitraryError ( ) ) , . failRequest( ArbitraryError ( ) , . close) )
547
+ XCTAssertEqual ( state. channelInactive ( ) , . wait)
548
+ }
524
549
525
550
func testFailHTTP1RequestWithContentLengthWithNIOSSLErrorUncleanShutdownButIgnoreIt( ) {
526
551
var state = HTTPRequestStateMachine ( isChannelWritable: true )
0 commit comments