Created
June 14, 2014 01:12
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works very well if you're doing SSL Termination in AWS, and want to use
CookieSecure = CookieSecureOption.SameAsRequest,