{"action":"created","issue":{"url":"https://api.github.com/repos/netty/netty/issues/5734","repository_url":"https://api.github.com/repos/netty/netty","labels_url":"https://api.github.com/repos/netty/netty/issues/5734/labels{/name}","comments_url":"https://api.github.com/repos/netty/netty/issues/5734/comments","events_url":"https://api.github.com/repos/netty/netty/issues/5734/events","html_url":"https://github.com/netty/netty/issues/5734","id":172418984,"number":5734,"title":"Better way to access to the selected subprotocol in WebSocket server","user":{"login":"ktonga","id":1324947,"avatar_url":"https://avatars.githubusercontent.com/u/1324947?v=3","gravatar_id":"","url":"https://api.github.com/users/ktonga","html_url":"https://github.com/ktonga","followers_url":"https://api.github.com/users/ktonga/followers","following_url":"https://api.github.com/users/ktonga/following{/other_user}","gists_url":"https://api.github.com/users/ktonga/gists{/gist_id}","starred_url":"https://api.github.com/users/ktonga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ktonga/subscriptions","organizations_url":"https://api.github.com/users/ktonga/orgs","repos_url":"https://api.github.com/users/ktonga/repos","events_url":"https://api.github.com/users/ktonga/events{/privacy}","received_events_url":"https://api.github.com/users/ktonga/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-22T10:30:43Z","updated_at":"2016-08-22T10:59:09Z","closed_at":null,"body":"I'm implementing a WS server which supports several message formats, the client has to specify which one should be used configuring the connection subprotocol.\r\n\r\nI don't know if I missing something, but the only way I found to get the selected subprotocol seems a little bit dirty to my taste. The snippet is in Scala but should have no mayor differences with Java:\r\n\r\n```scala\r\nval handshakerKey: AttributeKey[WebSocketServerHandshaker] =\r\n    AttributeKey.valueOf(classOf[WebSocketServerHandshaker], \"HANDSHAKER\")\r\n\r\noverride protected def userEventTriggered(ctx: ChannelHandlerContext, evt: Object): Unit = {\r\n    if (HANDSHAKE_COMPLETE == evt) {\r\n      Future {\r\n        // Sorry about this tricky hack, it's the only way I found to access the handshaker\r\n        // associated with the channel so I can ask it for the selected subprotocol.\r\n        // The thing is that for the time when we receive this event the handshaker wasn't\r\n        // set as a channel attribute yet. So we MUST wait for it for a few millis, and for\r\n        // some reason we MUST do it in a separate thread.\r\n        // See: [WebSocketServerProtocolHandshakeHandler.java:88](https://git.io/v6DcJ)\r\n        Thread.sleep(500)\r\n        val subprotocol = ctx.channel().attr(handshakerKey).get().selectedSubprotocol()\r\n        \r\n        // Do stuff with the subprotocol name\r\n        ...\r\n      }\r\n    }\r\n  }\r\n``` \r\n\r\nMaybe a better approach for something like this would be to make the selected subprotocol available within the `HANDSHAKE_COMPLETE` event since it can be any object according to `userEventTriggered` signature.\r\n\r\nDoes it sound sensible to you guys?\r\nLet me know what you think.\r\n\r\nThanks.\r\n"},"comment":{"url":"https://api.github.com/repos/netty/netty/issues/comments/241379659","html_url":"https://github.com/netty/netty/issues/5734#issuecomment-241379659","issue_url":"https://api.github.com/repos/netty/netty/issues/5734","id":241379659,"user":{"login":"normanmaurer","id":439362,"avatar_url":"https://avatars.githubusercontent.com/u/439362?v=3","gravatar_id":"","url":"https://api.github.com/users/normanmaurer","html_url":"https://github.com/normanmaurer","followers_url":"https://api.github.com/users/normanmaurer/followers","following_url":"https://api.github.com/users/normanmaurer/following{/other_user}","gists_url":"https://api.github.com/users/normanmaurer/gists{/gist_id}","starred_url":"https://api.github.com/users/normanmaurer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/normanmaurer/subscriptions","organizations_url":"https://api.github.com/users/normanmaurer/orgs","repos_url":"https://api.github.com/users/normanmaurer/repos","events_url":"https://api.github.com/users/normanmaurer/events{/privacy}","received_events_url":"https://api.github.com/users/normanmaurer/received_events","type":"User","site_admin":false},"created_at":"2016-08-22T10:59:09Z","updated_at":"2016-08-22T10:59:09Z","body":"@ktonga yeah sounds like a good idea. Would you be interested to come up with a PR for this ?"}}
{"actor":{"display_login":"normanmaurer"}}