jellyfin/Jellyfin.Api/Middleware/QueryStringDecodingMiddleware.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2021-05-05 14:52:39 -07:00
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
2023-01-31 04:18:10 -07:00
namespace Jellyfin.Api.Middleware;
/// <summary>
/// URL decodes the querystring before binding.
/// </summary>
public class QueryStringDecodingMiddleware
2021-05-05 14:52:39 -07:00
{
2023-01-31 04:18:10 -07:00
private readonly RequestDelegate _next;
2021-05-05 14:52:39 -07:00
/// <summary>
2023-01-31 04:18:10 -07:00
/// Initializes a new instance of the <see cref="QueryStringDecodingMiddleware"/> class.
2021-05-05 14:52:39 -07:00
/// </summary>
2023-01-31 04:18:10 -07:00
/// <param name="next">The next delegate in the pipeline.</param>
public QueryStringDecodingMiddleware(RequestDelegate next)
2021-05-05 14:52:39 -07:00
{
2023-01-31 04:18:10 -07:00
_next = next;
}
2021-05-05 14:52:39 -07:00
2023-01-31 04:18:10 -07:00
/// <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)
{
var feature = httpContext.Features.Get<IQueryFeature>();
if (feature is not null)
2021-05-05 14:52:39 -07:00
{
2023-01-31 04:18:10 -07:00
httpContext.Features.Set<IQueryFeature>(new UrlDecodeQueryFeature(feature));
2021-05-05 14:52:39 -07:00
}
2023-01-31 04:18:10 -07:00
await _next(httpContext).ConfigureAwait(false);
2021-05-05 14:52:39 -07:00
}
}