Skip to content

Commit

Permalink
Made changes requested by yellis for readability and code cleanliness.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Nelson committed May 29, 2014
1 parent 8607fe0 commit 64ea0df
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions StackExchange.Profiling/IpAddressProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Web;
using System;
using System.Web;

namespace StackExchange.Profiling
{
Expand All @@ -16,8 +17,15 @@ public class IpAddressIdentity : IUserProvider
/// </summary>
public string GetUser(HttpRequest request)
{
return string.Format("{0}, {1}", request.ServerVariables["REMOTE_ADDR"] ?? "",
request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? "");
// If there's no X_FORWARDED_FOR header, just return REMOTE_ADDR
if (String.IsNullOrWhiteSpace(request.ServerVariables["HTTP_X_FORWARDED_FOR"]))
{
return request.ServerVariables["REMOTE_ADDR"] ?? "";
}

// Otherwise return the concatenation of the REMOTE_ADDR and the X_FORWARDED_FOR header
return string.Format("{0} - {1}", request.ServerVariables["REMOTE_ADDR"] ?? "",
request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
}
}
}

0 comments on commit 64ea0df

Please sign in to comment.