diff --git a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/LowLevelOutgoingConnectionSpec.scala b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/LowLevelOutgoingConnectionSpec.scala index 16986a113..268e90635 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/LowLevelOutgoingConnectionSpec.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/LowLevelOutgoingConnectionSpec.scala @@ -32,6 +32,12 @@ import pekko.http.scaladsl.model.HttpEntity._ import pekko.http.scaladsl.model.HttpMethods._ import pekko.http.scaladsl.model._ import pekko.http.scaladsl.model.headers._ +import pekko.http.impl.engine.rendering.{ + DateHeaderRendering, + HttpResponseRendererFactory, + ResponseRenderingContext, + ResponseRenderingOutput +} import pekko.http.impl.util._ import pekko.testkit._ @@ -634,6 +640,32 @@ class LowLevelOutgoingConnectionSpec extends PekkoSpecWithMaterializer with Insi netInSub.expectCancellation() } + "fail a chunked response entity when the connection closes before the first chunk" in new TestSetup { + sendStandardRequest() + + // The peer starts a normal response, but its application has not produced a body chunk yet. + val response = HttpResponse(entity = Chunked(ContentTypes.`application/octet-stream`, Source.maybe)) + val ResponseRenderingOutput.HttpData(initialHeaders) = Source.single(ResponseRenderingContext(response)) + .via(new HttpResponseRendererFactory(None, 256, NoLogging, DateHeaderRendering()).renderer) + .runWith(Sink.head) + .awaitResult(3.seconds.dilated) + sendWireData(initialHeaders) + + val received = expectResponse() + received.status shouldBe StatusCodes.OK + val Chunked(_, chunks) = received.entity + val probe = TestSubscriber.manualProbe[ChunkStreamPart]() + chunks.runWith(Sink.fromSubscriber(probe)) + probe.expectSubscription().request(1) + + closeNetworkInput() + + probe.expectError() shouldBe an[EntityStreamException] + responses.expectComplete() + netOut.expectComplete() + requestsSub.expectCancellation() + } + for ((phase, lineEnding) <- List( "before the status line ends" -> "", "after the status line but before the headers end" -> "\r\n"))