@@ -451,6 +451,60 @@ class HTTPRequestStateMachineTests: XCTestCase {
451
451
XCTAssertEqual ( state. errorHappened ( NIOSSLError . uncleanShutdown) , . failRequest( NIOSSLError . uncleanShutdown, . close) )
452
452
XCTAssertEqual ( state. requestCancelled ( ) , . wait, " A cancellation that happens to late is ignored " )
453
453
}
454
+
455
+ func testCanReadHTTP1_0ResponseWithoutBody( ) {
456
+ var state = HTTPRequestStateMachine ( isChannelWritable: true )
457
+ let requestHead = HTTPRequestHead ( version: . http1_1, method: . GET, uri: " / " )
458
+ let metadata = RequestFramingMetadata ( connectionClose: false , body: . none)
459
+ XCTAssertEqual ( state. startRequest ( head: requestHead, metadata: metadata) , . sendRequestHead( requestHead, startBody: false ) )
460
+
461
+ let responseHead = HTTPResponseHead ( version: . http1_0, status: . internalServerError)
462
+ XCTAssertEqual ( state. channelRead ( . head( responseHead) ) , . forwardResponseHead( responseHead, pauseRequestBodyStream: false ) )
463
+ XCTAssertEqual ( state. demandMoreResponseBodyParts ( ) , . wait)
464
+ XCTAssertEqual ( state. channelReadComplete ( ) , . wait)
465
+ XCTAssertEqual ( state. read ( ) , . read)
466
+ XCTAssertEqual ( state. channelReadComplete ( ) , . wait)
467
+ XCTAssertEqual ( state. channelRead ( . end( nil ) ) , . succeedRequest( . close, [ ] ) )
468
+ XCTAssertEqual ( state. channelInactive ( ) , . wait)
469
+ }
470
+
471
+ func testCanReadHTTP1_0ResponseWithBody( ) {
472
+ var state = HTTPRequestStateMachine ( isChannelWritable: true )
473
+ let requestHead = HTTPRequestHead ( version: . http1_1, method: . GET, uri: " / " )
474
+ let metadata = RequestFramingMetadata ( connectionClose: false , body: . none)
475
+ XCTAssertEqual ( state. startRequest ( head: requestHead, metadata: metadata) , . sendRequestHead( requestHead, startBody: false ) )
476
+
477
+ let responseHead = HTTPResponseHead ( version: . http1_0, status: . internalServerError)
478
+ let body = ByteBuffer ( string: " foo bar " )
479
+ XCTAssertEqual ( state. channelRead ( . head( responseHead) ) , . forwardResponseHead( responseHead, pauseRequestBodyStream: false ) )
480
+ XCTAssertEqual ( state. demandMoreResponseBodyParts ( ) , . wait)
481
+ XCTAssertEqual ( state. channelReadComplete ( ) , . wait)
482
+ XCTAssertEqual ( state. read ( ) , . read)
483
+ XCTAssertEqual ( state. channelReadComplete ( ) , . wait)
484
+ XCTAssertEqual ( state. channelRead ( . body( body) ) , . wait)
485
+ XCTAssertEqual ( state. channelRead ( . end( nil ) ) , . succeedRequest( . close, [ body] ) )
486
+ XCTAssertEqual ( state. channelInactive ( ) , . wait)
487
+ }
488
+
489
+ func testFailHTTP1_0RequestThatIsStillUploading( ) {
490
+ var state = HTTPRequestStateMachine ( isChannelWritable: true )
491
+ let requestHead = HTTPRequestHead ( version: . http1_1, method: . POST, uri: " / " )
492
+ let metadata = RequestFramingMetadata ( connectionClose: false , body: . stream)
493
+ XCTAssertEqual ( state. startRequest ( head: requestHead, metadata: metadata) , . sendRequestHead( requestHead, startBody: true ) )
494
+
495
+ let part1 : ByteBuffer = . init( string: " foo " )
496
+ XCTAssertEqual ( state. requestStreamPartReceived ( . byteBuffer( part1) ) , . sendBodyPart( . byteBuffer( part1) ) )
497
+ let responseHead = HTTPResponseHead ( version: . http1_0, status: . ok)
498
+ let body = ByteBuffer ( string: " foo bar " )
499
+ XCTAssertEqual ( state. channelRead ( . head( responseHead) ) , . forwardResponseHead( responseHead, pauseRequestBodyStream: false ) )
500
+ XCTAssertEqual ( state. demandMoreResponseBodyParts ( ) , . wait)
501
+ XCTAssertEqual ( state. channelReadComplete ( ) , . wait)
502
+ XCTAssertEqual ( state. read ( ) , . read)
503
+ XCTAssertEqual ( state. channelReadComplete ( ) , . wait)
504
+ XCTAssertEqual ( state. channelRead ( . body( body) ) , . wait)
505
+ XCTAssertEqual ( state. channelRead ( . end( nil ) ) , . failRequest( HTTPClientError . remoteConnectionClosed, . close) )
506
+ XCTAssertEqual ( state. channelInactive ( ) , . wait)
507
+ }
454
508
}
455
509
456
510
extension HTTPRequestStateMachine . Action : Equatable {
0 commit comments