QueryStringDecodingMiddleware.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Threading.Tasks;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Http.Features;
  5. using Microsoft.Extensions.Logging;
  6. namespace Jellyfin.Server.Middleware
  7. {
  8. /// <summary>
  9. /// URL decodes the querystring before binding.
  10. /// </summary>
  11. public class QueryStringDecodingMiddleware
  12. {
  13. private readonly RequestDelegate _next;
  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. {
  20. _next = next;
  21. }
  22. /// <summary>
  23. /// Executes the middleware action.
  24. /// </summary>
  25. /// <param name="httpContext">The current HTTP context.</param>
  26. /// <returns>The async task.</returns>
  27. public async Task Invoke(HttpContext httpContext)
  28. {
  29. httpContext.Features.Set<IQueryFeature>(new UrlDecodeQueryFeature(httpContext.Features.Get<IQueryFeature>()));
  30. await _next(httpContext).ConfigureAwait(false);
  31. }
  32. }
  33. }