EncoderController.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. namespace Jellyfin.Server.Integration.Tests.Controllers
  6. {
  7. /// <summary>
  8. /// Controller for testing the encoded url.
  9. /// </summary>
  10. public class EncoderController : BaseJellyfinTestController
  11. {
  12. /// <summary>
  13. /// Tests the url decoding.
  14. /// </summary>
  15. /// <param name="params">Parameters to echo back in the response.</param>
  16. /// <returns>An <see cref="OkResult"/>.</returns>
  17. /// <response code="200">Information retrieved.</response>
  18. [HttpGet("UrlDecode")]
  19. [ProducesResponseType(StatusCodes.Status200OK)]
  20. public ContentResult TestUrlDecoding([FromQuery] Dictionary<string, string>? @params = null)
  21. {
  22. return new ContentResult()
  23. {
  24. Content = (@params is not null && @params.Count > 0)
  25. ? string.Join("&", @params.Select(x => x.Key + "=" + x.Value))
  26. : string.Empty,
  27. ContentType = "text/plain; charset=utf-8",
  28. StatusCode = 200
  29. };
  30. }
  31. /// <summary>
  32. /// Tests the url decoding.
  33. /// </summary>
  34. /// <param name="params">Parameters to echo back in the response.</param>
  35. /// <returns>An <see cref="OkResult"/>.</returns>
  36. /// <response code="200">Information retrieved.</response>
  37. [HttpGet("UrlArrayDecode")]
  38. [ProducesResponseType(StatusCodes.Status200OK)]
  39. public ContentResult TestUrlArrayDecoding([FromQuery] Dictionary<string, string[]>? @params = null)
  40. {
  41. return new ContentResult()
  42. {
  43. Content = (@params is not null && @params.Count > 0)
  44. ? string.Join("&", @params.Select(x => x.Key + "=" + string.Join(',', x.Value)))
  45. : string.Empty,
  46. ContentType = "text/plain; charset=utf-8",
  47. StatusCode = 200
  48. };
  49. }
  50. }
  51. }