summaryrefslogtreecommitdiffstats
path: root/src/IOL.Helpers/HttpRequestHelpers.cs
blob: 5a0e1457ea8c1900bceabc3c447f9ed07cd40596 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System;
using Microsoft.AspNetCore.Http;

namespace IOL.Helpers
{
	public static class HttpRequestHelpers
	{
		public static string GetAppHost(this HttpRequest request) {
			var forwardedHostHeader = request.Headers["X-Forwarded-Host"].ToString();
			var forwardedProtoHeader = request.Headers["X-Forwarded-Proto"].ToString();
			if (forwardedHostHeader.HasValue()) {
				return (forwardedProtoHeader ?? "https") + "://" + forwardedHostHeader;
			}

			return request.Scheme + "://" + request.Host;
		}
	}
}