parent
bae2f2280a
commit
ce04a1a723
|
|
@ -111,6 +111,13 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
|||
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))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -473,17 +473,12 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
|||
MediaTypeHeaderValue contentType,
|
||||
MemoryStream responseStream = null)
|
||||
{
|
||||
var request = new Mock<HttpRequest>();
|
||||
var headers = new HeaderDictionary();
|
||||
request.Setup(r => r.ContentType).Returns(contentType.ToString());
|
||||
request.SetupGet(r => r.Headers).Returns(headers);
|
||||
headers[HeaderNames.AcceptCharset] = contentType.Charset.ToString();
|
||||
var response = new Mock<HttpResponse>();
|
||||
response.SetupGet(f => f.Body).Returns(responseStream ?? new MemoryStream());
|
||||
var httpContext = new Mock<HttpContext>();
|
||||
httpContext.SetupGet(c => c.Request).Returns(request.Object);
|
||||
httpContext.SetupGet(c => c.Response).Returns(response.Object);
|
||||
return new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||
var context = new DefaultHttpContext();
|
||||
context.Request.ContentType = contentType.ToString();
|
||||
context.Request.Headers[HeaderNames.AcceptCharset] = contentType.Charset.ToString();
|
||||
context.Response.Body = responseStream ?? new MemoryStream();
|
||||
|
||||
return new ActionContext(context, new RouteData(), new ActionDescriptor());
|
||||
}
|
||||
|
||||
private class TestableJsonOutputFormatter : NewtonsoftJsonOutputFormatter
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
{
|
||||
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"
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace FormatterWebSite.Controllers
|
|||
{
|
||||
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"
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue