jellyfin/Jellyfin.Api/Middleware/QueryStringDecodingMiddlewa...

40 lines
1.2 KiB
C#
Raw Normal View History

2021-05-05 17:52:39 -04:00
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
2023-01-13 21:37:37 -05:00
namespace Jellyfin.Api.Middleware
2021-05-05 17:52:39 -04:00
{
/// <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 18:15:24 -04:00
public QueryStringDecodingMiddleware(RequestDelegate next)
2021-05-05 17:52:39 -04: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 09:11:46 -05:00
var feature = httpContext.Features.Get<IQueryFeature>();
2022-12-05 09:01:13 -05:00
if (feature is not null)
2021-02-14 09:11:46 -05:00
{
httpContext.Features.Set<IQueryFeature>(new UrlDecodeQueryFeature(feature));
}
2021-05-05 17:52:39 -04:00
await _next(httpContext).ConfigureAwait(false);
}
}
}