mirror of https://github.com/abpframework/abp.git
10 changed files with 197 additions and 18 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,27 @@ |
|||
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) |
|||
{ |
|||
var stream = new InternalRemoteStreamContent(context.HttpContext); |
|||
return InputFormatterResult.SuccessAsync(stream); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
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 override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context) |
|||
{ |
|||
var httpContext = context.HttpContext; |
|||
var remoteStream = context.Object as IRemoteStreamContent; |
|||
using (var stream = remoteStream.GetStream()) |
|||
await stream.CopyToAsync(httpContext.Response.Body); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System; |
|||
using System.IO; |
|||
|
|||
namespace Volo.Abp.Content |
|||
{ |
|||
public interface IRemoteStreamContent |
|||
{ |
|||
string ContentType { get; } |
|||
long? ContentLength { get; } |
|||
Stream GetStream(); |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
using System; |
|||
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,15 @@ |
|||
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