src/Library/NetPro.Web.Api/Compression/ResponseCompressionVaryWorkaroundMiddleware.cs
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
using System.NetPro;
using System.Threading.Tasks;
namespace NetPro.Web.Api
{
/// <summary>
/// 请求返回压缩中间件
/// </summary>
public class ResponseCompressionVaryWorkaroundMiddleware
{
#region Fields
private readonly RequestDelegate _next;
#endregion
#region Ctor
/// <summary>
/// Ctor
/// </summary>
/// <param name="next">Next</param>
public ResponseCompressionVaryWorkaroundMiddleware(RequestDelegate next)
{
_next = next;
}
#endregion
#region Methods
/// <summary>
/// Invoke middleware actions
/// </summary>
/// <param name="context">HTTP context</param>
/// <param name="webHelper">Web helper</param>
/// <returns>Task</returns>
public async Task Invoke(HttpContext context, IWebHelper webHelper)
{
//TODO remove this code once upgraded to the latest version of Microsoft.AspNetCore.ResponseCompression (already fixed there)
// If the Accept-Encoding header is present, always add the Vary header
// This will be added as a feature in the next release of the middleware.
// https://github.com/aspnet/BasicMiddleware/issues/187
//find more at https://docs.microsoft.com/en-us/aspnet/core/performance/response-compression
var accept = context.Request.Headers[HeaderNames.AcceptEncoding];
if (!StringValues.IsNullOrEmpty(accept))
{
context.Response.Headers.Append(HeaderNames.Vary, HeaderNames.AcceptEncoding);
}
await _next(context);
}
#endregion
后面还有 2 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。