NVentimiglia / Websockets.PCL

C# Websockets for all platforms using native bridges
MIT License
98 stars 36 forks source link

Headers and cookies #7

Closed ghost closed 8 years ago

ghost commented 8 years ago

Is there a possibility of being able to access the connections headers and cookies?

As this would be very useful for cookie authenticated connections.

I myself rely on the cookie system to allow my users to connect via browser or by what I am working on currently a Xamarin Forms app.

Your websocket dll seems to be the most stable over all the others I have seen.

So I hope that I can end up using this PCL as finding PCLs that do websocket client side is dragging my development time quite a bit

NVentimiglia commented 8 years ago

Websockets.PCL is a wrapper around SocketRocket and AndroidAsync. Taking a look at those library we could in theory pass a dictionary of headers and cookies to the underlying implementation.

That said, I am not sure when I will have to make the changes (pretty busy at the moment). I will accept any pull requests if you want to go ahead and implement the feature.

Alternatively, you can pass your auth token as a query string or in an initial message.

ghost commented 8 years ago

Thanks for the reply.

Will look into it when I get home

Can you point me to a good starting point as I got a little lost when I looked at the source initially.

Thanks

NVentimiglia commented 8 years ago

https://github.com/NVentimiglia/Websockets.PCL/blob/master/Websockets/IWebSocketConnection.cs

Is the interface that all of the implementations implement. Open will need to include your header dictionary.

We pass this to a C# bridge. Parts of this gets auto generated by the binding library. might want to get do the next step first. https://github.com/NVentimiglia/Websockets.PCL/blob/master/Websockets.Droid/WebsocketConnection.cs

Received by a Java Bridge ( I use IntellIJ here) https://github.com/NVentimiglia/Websockets.PCL/blob/master/Websockets.DroidBridge/src/websockets/DroidBridge/BridgeController.java#L42

Use the Android Async API

https://github.com/NVentimiglia/Websockets.PCL/blob/master/Websockets.DroidBridge/src/websockets/DroidBridge/BridgeController.java#L65

https://github.com/koush/AndroidAsync

The same steps are mirrored for all the other platforms.

NVentimiglia commented 8 years ago

I did some more looking into AndroidAsync (I figured that would be the first gotcha). Im not sure now about the header support for websockets. (The API was not obvious) Will raise a question with them.

https://github.com/loopj/android-async-http/issues/1144

ghost commented 8 years ago

Ah ok thanks.

This seems like it would take some time. More than I have to get my app ready. So on server side I'll get it to recieve a json string and add cookies that way for now then I should be able to work on this once the app is out. Will keep you up to date