Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
If the request contains X-Forwarded-* headers then use those to build…
Browse files Browse the repository at this point in the history
… the DirectoryPath
  • Loading branch information
slewis74 committed Nov 10, 2016
1 parent 41c68b3 commit 861d0aa
Showing 1 changed file with 13 additions and 2 deletions.
@@ -1,4 +1,5 @@
using Nancy;
using System.Linq;
using Nancy;

namespace Octopus.Server.Extensibility.HostServices.Web
{
Expand All @@ -11,7 +12,17 @@ public static class NancyRequestExtensions
/// <returns>The full virtual directory path.</returns>
public static string DirectoryPath(this Request request)
{
return request.Url.SiteBase + request.Url.BasePath;
var urlSiteBase = request.Url.SiteBase;

var forwardedHost = request.Headers["X-Forwarded-Host"].FirstOrDefault();
if (forwardedHost != null)
{
var forwardedProto = request.Headers["X-Forwarded-Proto"].FirstOrDefault();

This comment has been minimized.

Copy link
@matt-richardson

matt-richardson Nov 10, 2016

Contributor

You're not guaranteed to get this header... You'll need a fallback here


urlSiteBase = $"{forwardedProto}://{forwardedHost}";
}

return urlSiteBase + request.Url.BasePath;
}
}
}

1 comment on commit 861d0aa

@matt-richardson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need some docs to go with this, methinks

Please sign in to comment.