| | | 1 | | using System.Threading.Tasks; |
| | | 2 | | using Microsoft.AspNetCore.Http; |
| | | 3 | | using Microsoft.AspNetCore.Http.Features; |
| | | 4 | | |
| | | 5 | | namespace Jellyfin.Api.Middleware; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// URL decodes the querystring before binding. |
| | | 9 | | /// </summary> |
| | | 10 | | public class QueryStringDecodingMiddleware |
| | | 11 | | { |
| | | 12 | | private readonly RequestDelegate _next; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Initializes a new instance of the <see cref="QueryStringDecodingMiddleware"/> class. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <param name="next">The next delegate in the pipeline.</param> |
| | | 18 | | public QueryStringDecodingMiddleware(RequestDelegate next) |
| | | 19 | | { |
| | 21 | 20 | | _next = next; |
| | 21 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Executes the middleware action. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="httpContext">The current HTTP context.</param> |
| | | 27 | | /// <returns>The async task.</returns> |
| | | 28 | | public async Task Invoke(HttpContext httpContext) |
| | | 29 | | { |
| | | 30 | | var feature = httpContext.Features.Get<IQueryFeature>(); |
| | | 31 | | if (feature is not null) |
| | | 32 | | { |
| | | 33 | | httpContext.Features.Set<IQueryFeature>(new UrlDecodeQueryFeature(feature)); |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | await _next(httpContext).ConfigureAwait(false); |
| | | 37 | | } |
| | | 38 | | } |