IHttpRequestHeader header = webStream.getUpgradeRequestHeader();
// check origin header
String origin = header.getHeader("Origin");
if (!isAllowed(origin)) {
throw new BadMessageException(403);
}
// check the subprotocol
String subprotocol = header.getHeader("WebSocket-Protocol", "");
if (!subprotocol.equalsIgnoreCase("mySubprotocol.example.org")) {
throw new BadMessageException(501);
}
}
private boolean isAllowed(String origin) {
// check the origin