Skip to content

Instantly share code, notes, and snippets.

@runesoerensen
Created June 14, 2014 01:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runesoerensen/921bf766b76d7573fcd4 to your computer and use it in GitHub Desktop.
Save runesoerensen/921bf766b76d7573fcd4 to your computer and use it in GitHub Desktop.
Sample OWIN middleware that modifies requests based on standard nginx headers (used on AppHarbor)
public class AppHarborMiddleware : OwinMiddleware
{
public AppHarborMiddleware(OwinMiddleware next)
: base(next)
{
}
public override Task Invoke(IOwinContext context)
{
if (string.Equals(context.Request.Headers["X-Forwarded-Proto"], "https", StringComparison.InvariantCultureIgnoreCase))
{
context.Request.Scheme = "https";
}
var forwardedForHeader = context.Request.Headers["X-Forwarded-For"];
if (!string.IsNullOrEmpty(forwardedForHeader))
{
context.Request.RemoteIpAddress = forwardedForHeader;
}
return Next.Invoke(context);
}
}
@martinjt
Copy link

martinjt commented Jul 6, 2016

Works very well if you're doing SSL Termination in AWS, and want to use CookieSecure = CookieSecureOption.SameAsRequest,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment