Skip to content
Browse files

Added server variables to IRequest.

Fixes #438.
  • Loading branch information...
1 parent 7878dcb commit bfc04efb3a5eb014a982bad7f90551446c9ddf52 @davidfowl davidfowl committed Jun 17, 2012
View
8 SignalR.Hosting.AspNet/AspNetRequest.cs
@@ -48,6 +48,14 @@ public NameValueCollection Headers
}
}
+ public NameValueCollection ServerVariables
+ {
+ get
+ {
+ return _context.Request.ServerVariables;
+ }
+ }
+
public NameValueCollection Form
{
get
View
7 SignalR.Hosting.Memory/Request.cs
@@ -20,6 +20,7 @@ public Request(Uri uri, CancellationTokenSource clientTokenSource, Dictionary<st
_clientTokenSource = clientTokenSource;
Form = new NameValueCollection();
Headers = new NameValueCollection();
+ ServerVariables = new NameValueCollection();
QueryString = HttpUtility.ParseDelimited(Url.Query.TrimStart('?'));
if (postData != null)
@@ -81,6 +82,12 @@ public NameValueCollection Headers
get;
private set;
}
+
+ public NameValueCollection ServerVariables
+ {
+ get;
+ private set;
+ }
public NameValueCollection Form
{
View
14 SignalR.Hosting.Owin/OwinRequest.cs
@@ -20,13 +20,15 @@ public OwinRequest(IDictionary<string, object> environment, string body)
Url = BuildUrl(env);
Headers = new NameValueCollection();
+ // TODO: Fill this up
+ ServerVariables = new NameValueCollection();
foreach (var pair in headers)
{
foreach (var value in pair.Value)
{
- Headers.Add(pair.Key, value);
- }
+ Headers.Add(pair.Key, value);
+ }
}
_cookies = new CookieManager();
@@ -54,6 +56,12 @@ public NameValueCollection Headers
private set;
}
+ public NameValueCollection ServerVariables
+ {
+ get;
+ private set;
+ }
+
public NameValueCollection QueryString
{
get;
@@ -91,7 +99,7 @@ private Uri BuildUrl(Gate.Environment env)
public void AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
{
-
+
}
}
}
View
37 SignalR.Hosting.Self/HttpListenerRequestWrapper.cs
@@ -11,26 +11,25 @@ namespace SignalR.Hosting.Self
public class HttpListenerRequestWrapper : IRequest
{
private readonly HttpListenerRequest _httpListenerRequest;
- private readonly NameValueCollection _qs;
private NameValueCollection _form;
- private readonly NameValueCollection _headers;
- private readonly CookieCollectionWrapper _cookies;
public HttpListenerRequestWrapper(HttpListenerRequest httpListenerRequest, IPrincipal user)
{
_httpListenerRequest = httpListenerRequest;
- _qs = new NameValueCollection(httpListenerRequest.QueryString);
- _headers = new NameValueCollection(httpListenerRequest.Headers);
- _cookies = new CookieCollectionWrapper(_httpListenerRequest.Cookies);
+ QueryString = new NameValueCollection(httpListenerRequest.QueryString);
+ Headers = new NameValueCollection(httpListenerRequest.Headers);
+ Cookies = new CookieCollectionWrapper(_httpListenerRequest.Cookies);
+ ServerVariables = new NameValueCollection();
User = user;
+
+ // Set the client IP
+ ServerVariables["REMOTE_ADDR"] = _httpListenerRequest.RemoteEndPoint.Address.ToString();
}
public IRequestCookieCollection Cookies
{
- get
- {
- return _cookies;
- }
+ get;
+ private set;
}
public NameValueCollection Form
@@ -44,10 +43,14 @@ public NameValueCollection Form
public NameValueCollection Headers
{
- get
- {
- return _headers;
- }
+ get;
+ private set;
+ }
+
+ public NameValueCollection ServerVariables
+ {
+ get;
+ private set;
}
public Uri Url
@@ -60,10 +63,8 @@ public Uri Url
public NameValueCollection QueryString
{
- get
- {
- return _qs;
- }
+ get;
+ private set;
}
public IPrincipal User
View
5 SignalR/Hosting/IRequest.cs
@@ -26,6 +26,11 @@ public interface IRequest
NameValueCollection Headers { get; }
/// <summary>
+ /// Gets the server variables for this request.
+ /// </summary>
+ NameValueCollection ServerVariables { get; }
+
+ /// <summary>
/// Gets the form for this request.
/// </summary>
NameValueCollection Form { get; }
View
15 SignalR/Hubs/HubCallerContext.cs
@@ -11,20 +11,28 @@ public class HubCallerContext
public string ConnectionId { get; private set; }
/// <summary>
- /// Gets the cookies for the request
+ /// Gets the cookies for the request.
/// </summary>
public IRequestCookieCollection RequestCookies { get; private set; }
/// <summary>
- /// Gets the headers for the request
+ /// Gets the headers for the request.
/// </summary>
public NameValueCollection Headers { get; private set; }
/// <summary>
- /// Gets the querystring for the request
+ /// Gets the server variables for the request.
+ /// </summary>
+ public NameValueCollection ServerVariables { get; private set; }
+
+ /// <summary>
+ /// Gets the querystring for the request.
/// </summary>
public NameValueCollection QueryString { get; private set; }
+ /// <summary>
+ /// Gets the <see cref="IPrincipal"/> for the request.
+ /// </summary>
public IPrincipal User { get; private set; }
public HubCallerContext(IRequest request, string connectionId)
@@ -37,6 +45,7 @@ public HubCallerContext(IRequest request, string connectionId)
Headers = request.Headers;
QueryString = request.QueryString;
User = request.User;
+ ServerVariables = request.ServerVariables;
}
}
}
View
3 samples/SignalR.Hosting.AspNet.Samples/Raw/Raw.cs
@@ -20,10 +20,11 @@ protected override Task OnConnectedAsync(IRequest request, string connectionId)
_users[userNameCookie.Value] = connectionId;
}
+ string clientIp = request.ServerVariables["REMOTE_ADDR"];
string user = GetUser(connectionId);
return Groups.Add(connectionId, "foo").ContinueWith(_ =>
- Connection.Broadcast(DateTime.Now + ": " + user + " joined")).Unwrap();
+ Connection.Broadcast(DateTime.Now + ": " + user + " joined from " + clientIp)).Unwrap();
}
protected override Task OnReconnectedAsync(IRequest request, IEnumerable<string> groups, string connectionId)

0 comments on commit bfc04ef

Please sign in to comment.
Something went wrong with that request. Please try again.