WebSocket HTTP response handling

Showing 1-5 of 5 messages
WebSocket HTTP response handling Ahmed Soliman 6/24/13 1:42 PM
Dear Play!ers

I'm trying to get more sensible http-based control over the websocket connection, for example I want to handle authentication. If the *session* doesn't contain a certain key then I should return HTTP Forbidden on the websocket connection request. I cannot do that since the Websocket.using[T] requires the Tuple2[Iteratee, Enumerator] return type, I can return an EOF enumerator but that is not expressive and doesn't feel right to me.

I could do something similar using this snippet of code:

 def ws(username: String) = {
    if (username == "asoliman")
      Action { request =>
        Forbidden("Soliman is not allowed here")
      }
    else
      WebSocket.using[String] { request =>
        val in = Iteratee.foreach[String]( s => println("got: " + s)).mapDone(_ => println("Disconnected"))
        val out = Enumerator[String]("Ahmed", "Mohamed", "Ibrahim").andThen(Enumerator.enumInput(Input.EOF))
        (in, out)
      }
  }


and in the routes file I got:

GET     /ws/$username<.*>                         controllers.Application.ws(username)


So, the point here is that I could capture some parameter from the url and do my check, but I cannot access the "request" parameter at that point and this means I cannot read the session.

Any clue?
Ahmed Soliman - أحمد سليمان

http://www.ahmedsoliman.com
GPG ID: 0xAEEE5042

Plant a tree, save the planet and please don't print this message!
Re: WebSocket HTTP response handling Ahmed Soliman 6/24/13 1:56 PM
Sorry, forgot to add the version [Play 2.1.1]

Ahmed Soliman - أحمد سليمان

http://www.ahmedsoliman.com
GPG ID: 0xAEEE5042

Plant a tree, save the planet and please don't print this message!


Re: [play-framework] Re: WebSocket HTTP response handling Guillaume Bort 6/25/13 12:46 AM
Yes, it's not really possible right now with the current API. Anyway I don't think it really help to send a Forbidden response in this case as it will just make the Javascript WebSocket connection fail with an error. 

I would just send a EOF right away to forbid the WebSocket connection.


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Re: WebSocket HTTP response handling volker...@eligotech.com 6/25/13 11:33 PM
I was considering overwriting Global.onRouteRequest for a similar problem. At the end we decided to handle this through the returned content, so did not really try it out. But I assume it is possible as the RequestHeader is available there.
Re: WebSocket HTTP response handling Fabio Tiriticco 10/28/13 2:36 PM
Hi all, any news on this?