Skip to content

Commit

Permalink
Allow sync IO for NewtonsoftJsonOutputFormatter #8302
Browse files Browse the repository at this point in the history
  • Loading branch information
Tratcher committed Mar 7, 2019
1 parent 8aa0218 commit 581f9c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext co
throw new ArgumentNullException(nameof(selectedEncoding));
}

// Opt into sync IO support until we can work out an alternative https://github.com/aspnet/AspNetCore/issues/6397
var syncIOFeature = context.HttpContext.Features.Get<Http.Features.IHttpBodyControlFeature>();
if (syncIOFeature != null)
{
syncIOFeature.AllowSynchronousIO = true;
}

var response = context.HttpContext.Response;
using (var writer = context.WriterFactory(response.Body, selectedEncoding))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task JsonOutputFormatter_ReturnsIndentedJson()
{
Id = 1,
Alias = "john",
description = "Administrator",
description = "This is long so we can test large objects " + new string('a', 1024 * 65),
Designation = "Administrator",
Name = "John Williams"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public IActionResult ReturnsIndentedJson()
{
Id = 1,
Alias = "john",
description = "Administrator",
description = "This is long so we can test large objects " + new string('a', 1024 * 65),
Designation = "Administrator",
Name = "John Williams"
};
Expand Down

0 comments on commit 581f9c3

Please sign in to comment.