|
|
|
@ -1,5 +1,7 @@ |
|
|
|
using LINGYUN.Abp.Wrapper; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.Extensions.Logging.Abstractions; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
|
|
|
|
@ -7,29 +9,40 @@ namespace LINGYUN.Abp.AspNetCore.Wrapper; |
|
|
|
|
|
|
|
public class DefaultHttpResponseWrapper : IHttpResponseWrapper, ITransientDependency |
|
|
|
{ |
|
|
|
public ILogger<DefaultHttpResponseWrapper> Logger { protected get; set; } |
|
|
|
|
|
|
|
protected AbpWrapperOptions Options { get; } |
|
|
|
|
|
|
|
public DefaultHttpResponseWrapper(IOptions<AbpWrapperOptions> options) |
|
|
|
{ |
|
|
|
Options = options.Value; |
|
|
|
|
|
|
|
Logger = NullLogger<DefaultHttpResponseWrapper>.Instance; |
|
|
|
} |
|
|
|
|
|
|
|
public virtual void Wrap(HttpResponseWrapperContext context) |
|
|
|
{ |
|
|
|
context.HttpContext.Response.StatusCode = context.HttpStatusCode; |
|
|
|
if (context.HttpHeaders != null) |
|
|
|
if (!context.HttpContext.Response.HasStarted) |
|
|
|
{ |
|
|
|
foreach (var header in context.HttpHeaders) |
|
|
|
context.HttpContext.Response.StatusCode = context.HttpStatusCode; |
|
|
|
if (context.HttpHeaders != null) |
|
|
|
{ |
|
|
|
if (!context.HttpContext.Response.Headers.ContainsKey(header.Key)) |
|
|
|
foreach (var header in context.HttpHeaders) |
|
|
|
{ |
|
|
|
context.HttpContext.Response.Headers.Append(header.Key, header.Value); |
|
|
|
if (!context.HttpContext.Response.Headers.ContainsKey(header.Key)) |
|
|
|
{ |
|
|
|
context.HttpContext.Response.Headers.Append(header.Key, header.Value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!context.HttpContext.Response.Headers.ContainsKey(AbpHttpWrapConsts.AbpWrapResult)) |
|
|
|
{ |
|
|
|
context.HttpContext.Response.Headers.Append(AbpHttpWrapConsts.AbpWrapResult, "true"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!context.HttpContext.Response.Headers.ContainsKey(AbpHttpWrapConsts.AbpWrapResult)) |
|
|
|
else |
|
|
|
{ |
|
|
|
context.HttpContext.Response.Headers.Append(AbpHttpWrapConsts.AbpWrapResult, "true"); |
|
|
|
Logger.LogWarning("HTTP response has already started, cannot set headers and status code!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|