mirror of https://github.com/abpframework/abp.git
Browse Source
Support to return Stream from application services & handle on the Dynamic C# proxyingpull/5759/head
committed by
GitHub
11 changed files with 202 additions and 20 deletions
@ -0,0 +1,25 @@ |
|||||
|
using System.IO; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Volo.Abp.Content; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Content |
||||
|
{ |
||||
|
internal class InternalRemoteStreamContent : IRemoteStreamContent |
||||
|
{ |
||||
|
private readonly HttpContext _httpContext; |
||||
|
|
||||
|
public InternalRemoteStreamContent(HttpContext httpContext) |
||||
|
{ |
||||
|
_httpContext = httpContext; |
||||
|
} |
||||
|
|
||||
|
public string ContentType => _httpContext.Request.ContentType; |
||||
|
|
||||
|
public long? ContentLength => _httpContext.Request.ContentLength; |
||||
|
|
||||
|
public Stream GetStream() |
||||
|
{ |
||||
|
return _httpContext.Request.Body; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Net.Http.Headers; |
||||
|
using Microsoft.AspNetCore.Mvc.Formatters; |
||||
|
using Volo.Abp.Content; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Content |
||||
|
{ |
||||
|
public class RemoteStreamContentInputFormatter : InputFormatter |
||||
|
{ |
||||
|
public RemoteStreamContentInputFormatter() |
||||
|
{ |
||||
|
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("*/*")); |
||||
|
} |
||||
|
|
||||
|
protected override bool CanReadType(Type type) |
||||
|
{ |
||||
|
return typeof(IRemoteStreamContent) == type; |
||||
|
} |
||||
|
|
||||
|
public override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context) |
||||
|
{ |
||||
|
return InputFormatterResult.SuccessAsync( |
||||
|
new InternalRemoteStreamContent(context.HttpContext) |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc.Formatters; |
||||
|
using Microsoft.Net.Http.Headers; |
||||
|
using Volo.Abp.Content; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Content |
||||
|
{ |
||||
|
public class RemoteStreamContentOutputFormatter : OutputFormatter |
||||
|
{ |
||||
|
public RemoteStreamContentOutputFormatter() |
||||
|
{ |
||||
|
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("*/*")); |
||||
|
} |
||||
|
|
||||
|
protected override bool CanWriteType(Type type) |
||||
|
{ |
||||
|
return typeof(IRemoteStreamContent).IsAssignableFrom(type); |
||||
|
} |
||||
|
|
||||
|
public async override Task WriteResponseBodyAsync(OutputFormatterWriteContext context) |
||||
|
{ |
||||
|
var remoteStream = (IRemoteStreamContent)context.Object; |
||||
|
using (var stream = remoteStream.GetStream()) |
||||
|
{ |
||||
|
await stream.CopyToAsync(context.HttpContext.Response.Body); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
using System.IO; |
||||
|
|
||||
|
namespace Volo.Abp.Content |
||||
|
{ |
||||
|
public interface IRemoteStreamContent |
||||
|
{ |
||||
|
string ContentType { get; } |
||||
|
|
||||
|
long? ContentLength { get; } |
||||
|
|
||||
|
Stream GetStream(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
using System.IO; |
||||
|
|
||||
|
namespace Volo.Abp.Content |
||||
|
{ |
||||
|
public class RemoteStreamContent : IRemoteStreamContent |
||||
|
{ |
||||
|
private readonly Stream _stream; |
||||
|
|
||||
|
public RemoteStreamContent(Stream stream) |
||||
|
{ |
||||
|
_stream = stream; |
||||
|
} |
||||
|
|
||||
|
public virtual string ContentType { get; set; } |
||||
|
|
||||
|
public virtual long? ContentLength => _stream.Length; |
||||
|
|
||||
|
public virtual Stream GetStream() |
||||
|
{ |
||||
|
return _stream; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System.IO; |
||||
|
using Volo.Abp.Content; |
||||
|
|
||||
|
namespace Volo.Abp.Http.Client.Content |
||||
|
{ |
||||
|
internal class ReferencedRemoteStreamContent : RemoteStreamContent |
||||
|
{ |
||||
|
private readonly object[] _references; |
||||
|
|
||||
|
public ReferencedRemoteStreamContent(Stream stream, params object[] references) |
||||
|
: base(stream) |
||||
|
{ |
||||
|
this._references = references; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue