Permalink
Browse files

Change cookies to be IDictionary<string, Cookie>.

  • Loading branch information...
1 parent 5ec61eb commit c514bbe2063f57b8d23aad34c1e86852d69dd6a2 @davidfowl davidfowl committed Nov 28, 2012
View
7 samples/Microsoft.AspNet.SignalR.Hosting.AspNet.Samples/Raw/RawConnection.cs
@@ -13,8 +13,9 @@ public class RawConnection : PersistentConnection
protected override Task OnConnectedAsync(IRequest request, string connectionId)
{
- var userNameCookie = request.Cookies["user"];
- if (userNameCookie != null)
+ Cookie userNameCookie;
+ if (request.Cookies.TryGetValue("user", out userNameCookie) &&
+ userNameCookie != null)
{
_clients[connectionId] = userNameCookie.Value;
_users[userNameCookie.Value] = connectionId;
@@ -61,7 +62,7 @@ protected override Task OnReceivedAsync(IRequest request, string connectionId, s
type = MessageType.Broadcast.ToString(),
from = GetUser(connectionId),
data = message.Value
- },
+ },
connectionId);
break;
case MessageType.Send:
View
2 src/Microsoft.AspNet.SignalR.Core/Hosting/IRequest.cs
@@ -41,7 +41,7 @@ public interface IRequest
/// <summary>
/// Gets the cookies for this request.
/// </summary>
- IRequestCookieCollection Cookies { get; }
+ IDictionary<string, Cookie> Cookies { get; }
/// <summary>
/// Gets security information for the current HTTP request.
View
10 src/Microsoft.AspNet.SignalR.Core/Hosting/IRequestCookieCollection.cs
@@ -1,10 +0,0 @@
-// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
-
-namespace Microsoft.AspNet.SignalR
-{
- public interface IRequestCookieCollection
- {
- Cookie this[string name] { get; }
- int Count { get; }
- }
-}
View
3 src/Microsoft.AspNet.SignalR.Core/Hubs/HubCallerContext.cs
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
+using System.Collections.Generic;
using System.Collections.Specialized;
using System.Security.Principal;
@@ -15,7 +16,7 @@ public class HubCallerContext
/// <summary>
/// Gets the cookies for the request.
/// </summary>
- public IRequestCookieCollection RequestCookies
+ public IDictionary<string, Cookie> RequestCookies
{
get
{
View
1 src/Microsoft.AspNet.SignalR.Core/Microsoft.AspNet.SignalR.Core.csproj
@@ -64,7 +64,6 @@
<Compile Include="Hosting\HostContext.cs" />
<Compile Include="Hosting\HostContextExtensions.cs" />
<Compile Include="Hosting\Cookie.cs" />
- <Compile Include="Hosting\IRequestCookieCollection.cs" />
<Compile Include="Hosting\IRequest.cs" />
<Compile Include="Hosting\IResponse.cs" />
<Compile Include="CommandType.cs" />
View
17 src/Microsoft.AspNet.SignalR.Hosting.Memory/Request.cs
@@ -25,7 +25,7 @@ public Request(Uri uri, Action abort, Dictionary<string, string> postData, IPrin
Headers = new NameValueCollection();
ServerVariables = new NameValueCollection();
QueryString = HttpUtility.ParseDelimited(Url.Query.TrimStart('?'));
- Cookies = new RequestCookieCollection();
+ Cookies = new Dictionary<string, Cookie>();
Items = new Dictionary<string, object>();
if (postData != null)
@@ -102,7 +102,7 @@ public NameValueCollection Form
private set;
}
- public IRequestCookieCollection Cookies
+ public IDictionary<string, Cookie> Cookies
{
get;
private set;
@@ -125,18 +125,5 @@ public Task AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
// TODO: Add support
throw new NotSupportedException();
}
-
- private class RequestCookieCollection : IRequestCookieCollection
- {
- public Cookie this[string name]
- {
- get { return null; }
- }
-
- public int Count
- {
- get { return 0; }
- }
- }
}
}
View
1 src/Microsoft.AspNet.SignalR.Owin/Microsoft.AspNet.SignalR.Owin.csproj
@@ -61,7 +61,6 @@
<Compile Include="Handlers\PersistentConnectionHandler.cs" />
<Compile Include="Handlers\HubDispatcherHandler.cs" />
<Compile Include="ServerRequest.Owin.cs" />
- <Compile Include="ServerRequestCookieCollection.cs" />
<Compile Include="ServerRequest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServerResponse.cs" />
View
8 src/Microsoft.AspNet.SignalR.Owin/ServerRequest.cs
@@ -22,7 +22,7 @@ public partial class ServerRequest : IRequest
private NameValueCollection _form;
private bool _formInitialized;
private object _formLock;
- private ServerRequestCookieCollection _cookies;
+ private IDictionary<string, Cookie> _cookies;
public Uri Url
{
@@ -118,14 +118,14 @@ public NameValueCollection Form
}
- public IRequestCookieCollection Cookies
+ public IDictionary<string, Cookie> Cookies
{
get
{
return LazyInitializer.EnsureInitialized(
ref _cookies, () =>
{
- IDictionary<string, Cookie> cookies = new Dictionary<string, Cookie>();
+ var cookies = new Dictionary<string, Cookie>(StringComparer.OrdinalIgnoreCase);
var text = RequestHeaders.GetHeader("Cookie");
foreach (var kv in ParamDictionary.ParseToEnumerable(text, CommaSemicolon))
{
@@ -134,7 +134,7 @@ public IRequestCookieCollection Cookies
cookies.Add(kv.Key, new Cookie(kv.Key, kv.Value));
}
}
- return new ServerRequestCookieCollection(cookies);
+ return cookies;
});
}
}
View
30 src/Microsoft.AspNet.SignalR.Owin/ServerRequestCookieCollection.cs
@@ -1,30 +0,0 @@
-// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
-
-using System.Collections.Generic;
-
-namespace Microsoft.AspNet.SignalR.Owin
-{
- public class ServerRequestCookieCollection : IRequestCookieCollection
- {
- private readonly IDictionary<string, Cookie> _cookies;
-
- public ServerRequestCookieCollection(IDictionary<string, Cookie> cookies)
- {
- _cookies = cookies;
- }
-
- public Cookie this[string name]
- {
- get
- {
- Cookie value;
- return _cookies.TryGetValue(name, out value) ? value : null;
- }
- }
-
- public int Count
- {
- get { return _cookies.Count; }
- }
- }
-}
View
3 src/Microsoft.AspNet.SignalR.Owin45/Microsoft.AspNet.SignalR.Owin45.csproj
@@ -88,9 +88,6 @@
<Compile Include="..\Microsoft.AspNet.SignalR.Owin\ServerRequest.Owin.cs">
<Link>ServerRequest.Owin.cs</Link>
</Compile>
- <Compile Include="..\Microsoft.AspNet.SignalR.Owin\ServerRequestCookieCollection.cs">
- <Link>ServerRequestCookieCollection.cs</Link>
- </Compile>
<Compile Include="..\Microsoft.AspNet.SignalR.Owin\ServerResponse.cs">
<Link>ServerResponse.cs</Link>
</Compile>

0 comments on commit c514bbe

Please sign in to comment.