Play Framework WebSocket拒绝带有自定义错误代码的连接

def socket: WebSocket = {
    WebSocket.acceptOrResult[Message,Message] { implicit request: RequestHeader =>
      serviceUserIdentity.getUserIdentity(request) map {
        case Some(userIdentityPlay) if userIdentityPlay.hasValidLicense =>
          Right(
            actorFlow.actorRef(out =>
              actorWSServer.props(out)
            )
          )
        case Some(_) =>
          Left(Results(4403)) //invalid user
        case None =>
          Left(Results(4401)) //session expired
      } recover {
        case exception: Exception =>
          Left(InternalServerError)
      }
    }
  }

当用户没有有效的许可证或他的会话已过期时,我从服务器得到的CloseEvent

CloseEvent {isTrusted: true,wasClean: false,code: 1006,reason: "",type: "close", …}

似乎Result Http代码(4403)被覆盖为1006。

我期望的结果:

CloseEvent {isTrusted: true,code: 4403, …}

有没有办法在WebSocket.accept做到这一点? 还是使用play.api.http.websocket.CloseMessage的解决方法?

tc8030 回答:Play Framework WebSocket拒绝带有自定义错误代码的连接

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3123328.html

大家都在问