Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

51 righe
1.7 KiB

  1. // Copyright (c) .NET Core Community. All rights reserved.
  2. // Licensed under the MIT License. See License.txt in the project root for license information.
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Threading.Tasks;
  6. using Microsoft.AspNetCore.Http;
  7. namespace DotNetCore.CAP.Dashboard
  8. {
  9. public abstract class DashboardRequest
  10. {
  11. public abstract string Method { get; }
  12. public abstract string Path { get; }
  13. public abstract string PathBase { get; }
  14. public abstract string LocalIpAddress { get; }
  15. public abstract string RemoteIpAddress { get; }
  16. public abstract string GetQuery(string key);
  17. public abstract Task<IList<string>> GetFormValuesAsync(string key);
  18. }
  19. internal sealed class CapDashboardRequest : DashboardRequest
  20. {
  21. private readonly HttpContext _context;
  22. public CapDashboardRequest(HttpContext context)
  23. {
  24. _context = context ?? throw new ArgumentNullException(nameof(context));
  25. }
  26. public override string Method => _context.Request.Method;
  27. public override string Path => _context.Request.Path.Value;
  28. public override string PathBase => _context.Request.PathBase.Value;
  29. public override string LocalIpAddress => _context.Connection.LocalIpAddress.MapToIPv4().ToString();
  30. public override string RemoteIpAddress => _context.Connection.RemoteIpAddress.MapToIPv4().ToString();
  31. public override string GetQuery(string key)
  32. {
  33. return _context.Request.Query[key];
  34. }
  35. public override async Task<IList<string>> GetFormValuesAsync(string key)
  36. {
  37. var form = await _context.Request.ReadFormAsync();
  38. return form[key];
  39. }
  40. }
  41. }