summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-04-21 10:50:51 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-04-21 10:50:51 -0700
commit8f173adba793c6ef4efccb4ee21c17e24a442783 (patch)
treebea3b532b6c5beb817e092d69dc36c9ee6b6ae50
parent9d073f1dfb451fd2db6d060cd4d53c857098bb5a (diff)
downloadDotNetOpenAuth-8f173adba793c6ef4efccb4ee21c17e24a442783.zip
DotNetOpenAuth-8f173adba793c6ef4efccb4ee21c17e24a442783.tar.gz
DotNetOpenAuth-8f173adba793c6ef4efccb4ee21c17e24a442783.tar.bz2
Added better public-facing URL detection in web farms like Windows Azure.
-rw-r--r--src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs b/src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs
index 367c14f..e84a097 100644
--- a/src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs
+++ b/src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs
@@ -53,7 +53,7 @@ namespace DotNetOpenAuth.Messaging {
ErrorUtilities.VerifyArgumentNotNull(request, "request");
this.HttpMethod = request.HttpMethod;
- this.Url = request.Url;
+ this.Url = GetPublicFacingUrl(request);
this.RawUrl = request.RawUrl;
this.Headers = GetHeaderCollection(request.Headers);
this.InputStream = request.InputStream;
@@ -315,6 +315,39 @@ namespace DotNetOpenAuth.Messaging {
}
/// <summary>
+ /// Gets the public facing URL for the given incoming HTTP request.
+ /// </summary>
+ /// <param name="request">The request.</param>
+ /// <returns>The URI that the outside world used to create this request.</returns>
+ private static Uri GetPublicFacingUrl(HttpRequest request) {
+ Contract.Requires(request != null);
+ ErrorUtilities.VerifyArgumentNotNull(request, "request");
+
+ // Due to URL rewriting, cloud computing (i.e. Azure)
+ // and web farms, etc., we have to be VERY careful about what
+ // we consider the incoming URL. We want to see the URL as it would
+ // appear on the public-facing side of the hosting web site.
+ // HttpRequest.Url gives us the internal URL in a cloud environment,
+ // So we use a variable that (at least from what I can tell) gives us
+ // the public URL:
+ if (request.ServerVariables["HTTP_HOST"] != null) {
+ ErrorUtilities.VerifySupported(request.Url.Scheme == Uri.UriSchemeHttps || request.Url.Scheme == Uri.UriSchemeHttp, "Only HTTP and HTTPS are supported protocols.");
+ UriBuilder publicRequestUri = new UriBuilder(request.Url);
+ string[] hostAndPort = request.ServerVariables["HTTP_HOST"].Split(new[] { ':' }, 2);
+ publicRequestUri.Host = hostAndPort[0];
+ if (hostAndPort.Length > 1) {
+ publicRequestUri.Port = Convert.ToInt32(hostAndPort[1]);
+ } else {
+ publicRequestUri.Port = publicRequestUri.Scheme == Uri.UriSchemeHttps ? 443 : 80;
+ }
+ return publicRequestUri.Uri;
+ } else {
+ // Failover to the method that works for non-web farm enviroments.
+ return request.Url;
+ }
+ }
+
+ /// <summary>
/// Makes up a reasonable guess at the raw URL from the possibly rewritten URL.
/// </summary>
/// <param name="url">A full URL.</param>