jellyfin-server/Jellyfin.Server/Middleware/QueryStringDecodingMiddleware.cs

40 lines
1.2 KiB
C#
Raw Normal View History

2021-05-05 21:52:39 +00:00
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
namespace Jellyfin.Server.Middleware
{
/// <summary>
/// URL decodes the querystring before binding.
/// </summary>
public class QueryStringDecodingMiddleware
{
private readonly RequestDelegate _next;
/// <summary>
/// Initializes a new instance of the <see cref="QueryStringDecodingMiddleware"/> class.
/// </summary>
/// <param name="next">The next delegate in the pipeline.</param>
2021-05-05 22:15:24 +00:00
public QueryStringDecodingMiddleware(RequestDelegate next)
2021-05-05 21:52:39 +00:00
{
_next = next;
}
/// <summary>
/// Executes the middleware action.
/// </summary>
/// <param name="httpContext">The current HTTP context.</param>
/// <returns>The async task.</returns>
public async Task Invoke(HttpContext httpContext)
{
2021-02-14 14:11:46 +00:00
var feature = httpContext.Features.Get<IQueryFeature>();
if (feature != null)
{
httpContext.Features.Set<IQueryFeature>(new UrlDecodeQueryFeature(feature));
}
2021-05-05 21:52:39 +00:00
await _next(httpContext).ConfigureAwait(false);
}
}
}