factorization
This commit is contained in:
parent
cf5aa9a8d9
commit
51c3ea3f37
2 changed files with 32 additions and 15 deletions
29
src/Yavsc/Helpers/RequestHelpers.cs
Normal file
29
src/Yavsc/Helpers/RequestHelpers.cs
Normal file
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue