diff --git a/src/Marten.AspNetCore/QueryableExtensions.cs b/src/Marten.AspNetCore/QueryableExtensions.cs index b971c743f1..1e0f4251d3 100644 --- a/src/Marten.AspNetCore/QueryableExtensions.cs +++ b/src/Marten.AspNetCore/QueryableExtensions.cs @@ -59,15 +59,10 @@ public static async Task WriteArray( int onFoundStatus = 200 ) { - var stream = new MemoryStream(); - await queryable.StreamJsonArray(stream, context.RequestAborted).ConfigureAwait(false); - context.Response.StatusCode = onFoundStatus; - context.Response.ContentLength = stream.Length; context.Response.ContentType = contentType; - stream.Position = 0; - await stream.CopyToAsync(context.Response.Body, context.RequestAborted).ConfigureAwait(false); + await queryable.StreamJsonArray(context.Response.Body, context.RequestAborted).ConfigureAwait(false); } /// @@ -266,15 +261,10 @@ public static async Task WriteArray( int onFoundStatus = 200 ) { - var stream = new MemoryStream(); - await session.StreamJsonMany(query, stream, context.RequestAborted).ConfigureAwait(false); - context.Response.StatusCode = onFoundStatus; - context.Response.ContentLength = stream.Length; context.Response.ContentType = contentType; - stream.Position = 0; - await stream.CopyToAsync(context.Response.Body, context.RequestAborted).ConfigureAwait(false); + await session.StreamJsonMany(query, context.Response.Body, context.RequestAborted).ConfigureAwait(false); } /// @@ -285,7 +275,6 @@ public static async Task WriteArray( /// /// /// Defaults to 200 - /// public static async Task WriteJson( this IQuerySession session, string sql, @@ -295,14 +284,9 @@ public static async Task WriteJson( params object[] parameters ) { - var stream = new MemoryStream(); - _ = await session.StreamJson(stream, context.RequestAborted, sql, parameters).ConfigureAwait(false); - context.Response.StatusCode = onFoundStatus; - context.Response.ContentLength = stream.Length; context.Response.ContentType = contentType; - stream.Position = 0; - await stream.CopyToAsync(context.Response.Body, context.RequestAborted).ConfigureAwait(false); + await session.StreamJson(context.Response.Body, context.RequestAborted, sql, parameters).ConfigureAwait(false); } }