roadie/Roadie.Api.Services/HttpContext.cs

25 lines
868 B
C#
Raw Normal View History

2019-06-30 22:14:36 +00:00
using Microsoft.AspNetCore.Http;
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; }
2019-06-30 22:14:36 +00:00
2018-11-06 21:55:31 +00:00
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;
2019-06-30 22:14:36 +00:00
if (configuration.UseSSLBehindProxy) scheme = "https";
2019-01-12 00:27:49 +00:00
var host = urlHelper.ActionContext.HttpContext.Request.Host;
2019-05-29 22:25:40 +00:00
if (!string.IsNullOrEmpty(configuration.BehindProxyHost))
2019-06-30 22:14:36 +00:00
host = new HostString(configuration.BehindProxyHost);
BaseUrl = $"{scheme}://{host}";
ImageBaseUrl = $"{BaseUrl}/images";
}
2018-11-06 21:55:31 +00:00
}
}