@@ -557,6 +557,68 @@ class HTTPRequestStateMachineTests: XCTestCase {
557
557
XCTAssertEqual ( state. errorHappened ( HTTPParserError . invalidEOFState) , . failRequest( HTTPParserError . invalidEOFState, . close) )
558
558
XCTAssertEqual ( state. channelInactive ( ) , . wait)
559
559
}
560
+
561
+ func testFailHTTPRequestWithContentLengthBecauseOfChannelInactiveWaitingForDemand( ) {
562
+ var state = HTTPRequestStateMachine ( isChannelWritable: true , ignoreUncleanSSLShutdown: false )
563
+ let requestHead = HTTPRequestHead ( version: . http1_1, method: . GET, uri: " / " )
564
+ let metadata = RequestFramingMetadata ( connectionClose: false , body: . none)
565
+ XCTAssertEqual ( state. startRequest ( head: requestHead, metadata: metadata) , . sendRequestHead( requestHead, startBody: false ) )
566
+
567
+ let responseHead = HTTPResponseHead ( version: . http1_1, status: . ok, headers: [ " Content-Length " : " 50 " ] )
568
+ let body = ByteBuffer ( string: " foo bar " )
569
+ XCTAssertEqual ( state. channelRead ( . head( responseHead) ) , . forwardResponseHead( responseHead, pauseRequestBodyStream: false ) )
570
+ XCTAssertEqual ( state. demandMoreResponseBodyParts ( ) , . wait)
571
+ XCTAssertEqual ( state. channelReadComplete ( ) , . wait)
572
+ XCTAssertEqual ( state. read ( ) , . read)
573
+ XCTAssertEqual ( state. channelRead ( . body( body) ) , . wait)
574
+ XCTAssertEqual ( state. channelReadComplete ( ) , . forwardResponseBodyParts( [ body] ) )
575
+ XCTAssertEqual ( state. read ( ) , . wait)
576
+
577
+ XCTAssertEqual ( state. channelRead ( . body( ByteBuffer ( string: " baz lightyear " ) ) ) , . wait)
578
+ XCTAssertEqual ( state. channelReadComplete ( ) , . wait)
579
+ XCTAssertEqual ( state. channelInactive ( ) , . failRequest( HTTPClientError . remoteConnectionClosed, . none) )
580
+ }
581
+
582
+ func testFailHTTPRequestWithContentLengthBecauseOfChannelInactiveWaitingForRead( ) {
583
+ var state = HTTPRequestStateMachine ( isChannelWritable: true , ignoreUncleanSSLShutdown: false )
584
+ let requestHead = HTTPRequestHead ( version: . http1_1, method: . GET, uri: " / " )
585
+ let metadata = RequestFramingMetadata ( connectionClose: false , body: . none)
586
+ XCTAssertEqual ( state. startRequest ( head: requestHead, metadata: metadata) , . sendRequestHead( requestHead, startBody: false ) )
587
+
588
+ let responseHead = HTTPResponseHead ( version: . http1_1, status: . ok, headers: [ " Content-Length " : " 50 " ] )
589
+ let body = ByteBuffer ( string: " foo bar " )
590
+ XCTAssertEqual ( state. channelRead ( . head( responseHead) ) , . forwardResponseHead( responseHead, pauseRequestBodyStream: false ) )
591
+ XCTAssertEqual ( state. demandMoreResponseBodyParts ( ) , . wait)
592
+ XCTAssertEqual ( state. channelReadComplete ( ) , . wait)
593
+ XCTAssertEqual ( state. read ( ) , . read)
594
+ XCTAssertEqual ( state. channelRead ( . body( body) ) , . wait)
595
+ XCTAssertEqual ( state. channelReadComplete ( ) , . forwardResponseBodyParts( [ body] ) )
596
+ XCTAssertEqual ( state. demandMoreResponseBodyParts ( ) , . wait)
597
+
598
+ XCTAssertEqual ( state. channelRead ( . body( ByteBuffer ( string: " baz lightyear " ) ) ) , . wait)
599
+ XCTAssertEqual ( state. channelReadComplete ( ) , . wait)
600
+ XCTAssertEqual ( state. channelInactive ( ) , . failRequest( HTTPClientError . remoteConnectionClosed, . none) )
601
+ }
602
+
603
+ func testFailHTTPRequestWithContentLengthBecauseOfChannelInactiveWaitingForReadAndDemand( ) {
604
+ var state = HTTPRequestStateMachine ( isChannelWritable: true , ignoreUncleanSSLShutdown: false )
605
+ let requestHead = HTTPRequestHead ( version: . http1_1, method: . GET, uri: " / " )
606
+ let metadata = RequestFramingMetadata ( connectionClose: false , body: . none)
607
+ XCTAssertEqual ( state. startRequest ( head: requestHead, metadata: metadata) , . sendRequestHead( requestHead, startBody: false ) )
608
+
609
+ let responseHead = HTTPResponseHead ( version: . http1_1, status: . ok, headers: [ " Content-Length " : " 50 " ] )
610
+ let body = ByteBuffer ( string: " foo bar " )
611
+ XCTAssertEqual ( state. channelRead ( . head( responseHead) ) , . forwardResponseHead( responseHead, pauseRequestBodyStream: false ) )
612
+ XCTAssertEqual ( state. demandMoreResponseBodyParts ( ) , . wait)
613
+ XCTAssertEqual ( state. channelReadComplete ( ) , . wait)
614
+ XCTAssertEqual ( state. read ( ) , . read)
615
+ XCTAssertEqual ( state. channelRead ( . body( body) ) , . wait)
616
+ XCTAssertEqual ( state. channelReadComplete ( ) , . forwardResponseBodyParts( [ body] ) )
617
+
618
+ XCTAssertEqual ( state. channelRead ( . body( ByteBuffer ( string: " baz lightyear " ) ) ) , . wait)
619
+ XCTAssertEqual ( state. channelReadComplete ( ) , . wait)
620
+ XCTAssertEqual ( state. channelInactive ( ) , . failRequest( HTTPClientError . remoteConnectionClosed, . none) )
621
+ }
560
622
}
561
623
562
624
extension HTTPRequestStateMachine . Action : Equatable {
0 commit comments