QueryStringDecodingMiddleware.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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(
  19. RequestDelegate next)
  20. {
  21. _next = next;
  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. httpContext.Features.Set<IQueryFeature>(new UrlDecodeQueryFeature(httpContext.Features.Get<IQueryFeature>()));
  31. await _next(httpContext).ConfigureAwait(false);
  32. }
  33. }
  34. }