我正在尝试使用PlayFramework 2.2中的WebSockets。我想对初始请求进行一些检查,并可能返回适当的HTTP状态码。原则上,它看起来像this question中所问的那样:
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)
}
}
如前所述,这是不可能的,因为WebSocket的using
和async
需要返回一个Tuple2[Iteratee,Enumerator]
。
有没有推荐的方法? 或者,有没有办法发送 WebSocket的状态码?