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 }";
|
2018-11-18 16:40:52 +00:00
|
|
|
|
this.ImageBaseUrl = $"{ this.BaseUrl}/images";
|
2018-11-14 23:18:02 +00:00
|
|
|
|
}
|
2018-11-06 21:55:31 +00:00
|
|
|
|
}
|
2018-11-14 23:18:02 +00:00
|
|
|
|
}
|