Not a final solution,dealing with 403 status codes ...

This commit is contained in:
2020-10-17 23:40:37 +01:00
parent 9f5951e6c4
commit 7800d1a447
10 changed files with 253 additions and 81 deletions

View File

@ -0,0 +1,54 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features;
using Microsoft.Extensions.Logging;
namespace Yavsc
{
public class YaSendFileMiddleware
{
private readonly RequestDelegate _next;
private readonly ILogger _logger;
//
// Résumé :
// Creates a new instance of the SendFileMiddleware.
//
// Paramètres :
// next:
// The next middleware in the pipeline.
//
// loggerFactory:
// An Microsoft.Extensions.Logging.ILoggerFactory instance used to create loggers.
public YaSendFileMiddleware(RequestDelegate next, ILoggerFactory loggerFactory)
{
if (next == null)
{
throw new ArgumentNullException("next");
}
if (loggerFactory == null)
{
throw new ArgumentNullException("loggerFactory");
}
_next = next;
_logger = loggerFactory.CreateLogger<YaSendFileMiddleware>();
}
public Task Invoke(HttpContext context)
{
if (context.Response.StatusCode < 400 || context.Response.StatusCode >= 600 )
{
if (context.Features.Get<IHttpSendFileFeature>() == null)
{
context.Features.Set((IHttpSendFileFeature)new YaSendFileWrapper(context.Response.Body, _logger));
}
}
return _next(context);
}
}
}