roadie/Roadie.Api.Services/HttpContext.cs

28 lines
951 B
C#
Raw Normal View History

2018-11-06 21:55:31 +00:00
using Microsoft.AspNetCore.Mvc;
2019-01-12 00:27:49 +00:00
using Roadie.Library.Configuration;
2018-11-06 21:55:31 +00:00
using Roadie.Library.Utility;
namespace Roadie.Api.Services
{
public class HttpContext : IHttpContext
{
public string BaseUrl { get; set; }
public string ImageBaseUrl { get; set; }
2019-01-12 00:27:49 +00:00
public HttpContext(IRoadieSettings configuration, IUrlHelper urlHelper)
2018-11-06 21:55:31 +00:00
{
2019-01-12 00:27:49 +00:00
var scheme = urlHelper.ActionContext.HttpContext.Request.Scheme;
if (configuration.UseSSLBehindProxy)
{
scheme = "https";
}
var host = urlHelper.ActionContext.HttpContext.Request.Host;
if(!string.IsNullOrEmpty(configuration.BehindProxyHost))
{
host = new Microsoft.AspNetCore.Http.HostString(configuration.BehindProxyHost);
}
this.BaseUrl = $"{ scheme }://{ host }";
this.ImageBaseUrl = $"{ this.BaseUrl}/images";
}
2018-11-06 21:55:31 +00:00
}
}