diff --git a/Libraries/src/Amazon.Lambda.AspNetCoreServer/Internal/InvokeFeatures.cs b/Libraries/src/Amazon.Lambda.AspNetCoreServer/Internal/InvokeFeatures.cs index 293f26b6a..2635f5f1d 100644 --- a/Libraries/src/Amazon.Lambda.AspNetCoreServer/Internal/InvokeFeatures.cs +++ b/Libraries/src/Amazon.Lambda.AspNetCoreServer/Internal/InvokeFeatures.cs @@ -180,10 +180,8 @@ string IHttpResponseFeature.ReasonPhrase set; } - bool IHttpResponseFeature.HasStarted - { - get; - } + bool _hasStarted; + bool IHttpResponseFeature.HasStarted => _hasStarted; IHeaderDictionary IHttpResponseFeature.Headers { @@ -320,6 +318,7 @@ async Task IHttpResponseBodyFeature.SendFileAsync( Task IHttpResponseBodyFeature.StartAsync(CancellationToken cancellationToken) { + _hasStarted = true; return Task.CompletedTask; } #endregion diff --git a/Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/TestCallingWebAPI.cs b/Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/TestCallingWebAPI.cs index 658bd7f9b..467733787 100644 --- a/Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/TestCallingWebAPI.cs +++ b/Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/TestCallingWebAPI.cs @@ -486,6 +486,27 @@ public void EnsureTraceIdStaysTheSame() Assert.Equal(traceId1, traceId2); } + [Fact] + public void TestDefaultResponseHasStartedFalse() + { + var features = new InvokeFeatures(); + var response = (IHttpResponseFeature)features; + + Assert.False(response.HasStarted); + } + + [Fact] + public async Task TestStartAsyncSetsHasStartedTrue() + { + var features = new InvokeFeatures(); + var responseBody = (IHttpResponseBodyFeature)features; + + await responseBody.StartAsync(); + + var response = (IHttpResponseFeature)features; + Assert.True(response.HasStarted); + } + private async Task InvokeAPIGatewayRequest(string fileName, bool configureApiToReturnExceptionDetail = false) { return await InvokeAPIGatewayRequest(new TestLambdaContext(), fileName, configureApiToReturnExceptionDetail);