using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
namespace Jellyfin.Api.Middleware;
///
/// URL decodes the querystring before binding.
///
public class QueryStringDecodingMiddleware
{
private readonly RequestDelegate _next;
///
/// Initializes a new instance of the class.
///
/// The next delegate in the pipeline.
public QueryStringDecodingMiddleware(RequestDelegate next)
{
_next = next;
}
///
/// Executes the middleware action.
///
/// The current HTTP context.
/// The async task.
public async Task Invoke(HttpContext httpContext)
{
var feature = httpContext.Features.Get();
if (feature is not null)
{
httpContext.Features.Set(new UrlDecodeQueryFeature(feature));
}
await _next(httpContext).ConfigureAwait(false);
}
}