QueryStringDecodingMiddleware.cs 1.2 KB

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