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

39 lines
1.1 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-31 06:18:10 -05:00
namespace Jellyfin.Api.Middleware;
/// <summary>
/// URL decodes the querystring before binding.
/// </summary>
public class QueryStringDecodingMiddleware
2021-05-05 17:52:39 -04:00
{
2023-01-31 06:18:10 -05:00
private readonly RequestDelegate _next;
2021-05-05 17:52:39 -04:00
/// <summary>
2023-01-31 06:18:10 -05:00
/// Initializes a new instance of the <see cref="QueryStringDecodingMiddleware"/> class.
2021-05-05 17:52:39 -04:00
/// </summary>
2023-01-31 06:18:10 -05:00
/// <param name="next">The next delegate in the pipeline.</param>
public QueryStringDecodingMiddleware(RequestDelegate next)
2021-05-05 17:52:39 -04:00
{
2023-01-31 06:18:10 -05:00
_next = next;
}
2021-05-05 17:52:39 -04:00
2023-01-31 06:18:10 -05: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 17:52:39 -04:00
{
2023-01-31 06:18:10 -05:00
httpContext.Features.Set<IQueryFeature>(new UrlDecodeQueryFeature(feature));
2021-05-05 17:52:39 -04:00
}
2023-01-31 06:18:10 -05:00
await _next(httpContext).ConfigureAwait(false);
2021-05-05 17:52:39 -04:00
}
}