diff --git a/src/Yavsc/ApiControllers/accounting/AccountController.cs b/src/Yavsc/ApiControllers/accounting/AccountController.cs index e3e55a44..8f44d61c 100644 --- a/src/Yavsc/ApiControllers/accounting/AccountController.cs +++ b/src/Yavsc/ApiControllers/accounting/AccountController.cs @@ -154,22 +154,10 @@ namespace Yavsc.WebApi.Controllers return Ok(user); } - [HttpGet("~/api/myip"),Authorize] - public IActionResult MyIp () + [HttpGet("~/api/myhost"),Authorize] + public IActionResult MyHost () { - string ip = null; - - ip = Request.Headers["X-Forwarded-For"]; - - if (string.IsNullOrEmpty(ip)) { - ip = Request.Host.Value; - } else { // Using X-Forwarded-For last address - ip = ip.Split(',') - .Last() - .Trim(); - } - - return Ok(ip); + return Ok(new { host = Request.ForHost() }); } /// diff --git a/src/Yavsc/Helpers/RequestHelpers.cs b/src/Yavsc/Helpers/RequestHelpers.cs new file mode 100644 index 00000000..841418d5 --- /dev/null +++ b/src/Yavsc/Helpers/RequestHelpers.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; + +using Microsoft.Extensions.Logging; +using Microsoft.AspNet.Http; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Yavsc.ViewModels; +using Yavsc.Models; +using Microsoft.Data.Entity; +using System.Linq; + +namespace Yavsc.Helpers +{ + public static class RequestHelpers + { + // Check for some apache proxy header, if any + public static string ForHost(this HttpRequest request) { + string host = request.Headers["X-Forwarded-For"]; + if (string.IsNullOrEmpty(host)) { + host = request.Host.Value; + } else { // Using X-Forwarded-For last address + host = host.Split(',') + .Last() + .Trim(); + } + return host; + } + } +} \ No newline at end of file