Allow setting of Cookies on HttpWebRequest in SignalR.Client.Connection #205

Merged
merged 3 commits into from Feb 22, 2012

2 participants

@edchapel

We are using Cookies to store some client information that must be sent in each request to the hub. At the moment, we've copied a number of files to change SignalR.Client.Connection.PrepareRequest from internal to public. We looked at issue #27 but ICredentials doesn't work for us. Our implementation overrides the virtual:

private CookieCollection _cookies;

public override void PrepareRequest(HttpWebRequest request)
{
    if (_cookies != null)
    {
        var cookieContainer = request.CookieContainer
                                  ?? (request.CookieContainer = new CookieContainer());
        cookieContainer.Add(_cookies);
    }

    base.PrepareRequest(request);
}

Of course, there are a number of ways this could be done. We'd like to send a pull request but need your design opinion. Would you prefer:

1) Change PrepareRequest to be public virtual
2) Add CookieContainer { get; } to Connection and change PrepareRequest to add it to the request as it does the ICredentials

@edchapel edchapel pushed a commit that referenced this pull request Feb 22, 2012
Ed Chapel Issue #205: Changed PreprareRequest from internal to public virtual e261d77
@edchapel edchapel commented on the diff Feb 22, 2012
SignalR.Client/Connection.cs
@@ -57,6 +57,8 @@ public Connection(string url, string queryString)
_syncContext = SynchronizationContext.Current;
}
+ public CookieContainer CookieContainer { get; set; }
@edchapel
edchapel added a line comment Feb 22, 2012

I did not add this to IConnection to avoid a breaking change to inheritors.

@davidfowl
SignalR member
davidfowl added a line comment Feb 22, 2012

Who cares just add it.

@davidfowl
SignalR member
davidfowl added a line comment Feb 22, 2012

Also, check to make sure Silverlight and WindowsPhone support this property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@edchapel

Confirmed: CookieContainer is supported on Silverlight and WP7

@davidfowl davidfowl merged commit fc7c3ba into SignalR:master Feb 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment