Browse Source
Set `ContentLength` of `HttpContext.Response`
pull/12214/head
maliming
4 years ago
No known key found for this signature in database
GPG Key ID: 96224957E51C89E
2 changed files with
3 additions and
1 deletions
-
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ContentFormatters/RemoteStreamContentOutputFormatter.cs
-
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ContentFormatters/RemoteStreamContentTestController_Tests.cs
|
|
|
@ -18,13 +18,14 @@ public class RemoteStreamContentOutputFormatter : OutputFormatter |
|
|
|
return typeof(IRemoteStreamContent).IsAssignableFrom(type); |
|
|
|
} |
|
|
|
|
|
|
|
public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context) |
|
|
|
public async override Task WriteResponseBodyAsync(OutputFormatterWriteContext context) |
|
|
|
{ |
|
|
|
var remoteStream = (IRemoteStreamContent)context.Object; |
|
|
|
|
|
|
|
if (remoteStream != null) |
|
|
|
{ |
|
|
|
context.HttpContext.Response.ContentType = remoteStream.ContentType; |
|
|
|
context.HttpContext.Response.ContentLength = remoteStream.ContentLength; |
|
|
|
|
|
|
|
if (!remoteStream.FileName.IsNullOrWhiteSpace()) |
|
|
|
{ |
|
|
|
|
|
|
|
@ -16,6 +16,7 @@ public class RemoteStreamContentTestController_Tests : AspNetCoreMvcTestBase |
|
|
|
var result = await GetResponseAsync("/api/remote-stream-content-test/download"); |
|
|
|
result.Content.Headers.ContentType?.ToString().ShouldBe("application/rtf"); |
|
|
|
result.Content.Headers.ContentDisposition?.FileName.ShouldBe("download.rtf"); |
|
|
|
result.Content.Headers.ContentLength.ShouldBe("DownloadAsync".Length); |
|
|
|
(await result.Content.ReadAsStringAsync()).ShouldBe("DownloadAsync"); |
|
|
|
} |
|
|
|
|
|
|
|
|