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.
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:
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.comGPG ID: 0xAEEE5042
Plant a tree, save the planet and please don't print this message!