// TODO: need lightweight approach (end)
private void onNetBegin(
                BeginFW begin)
            {
                final long sequence = begin.sequence();
                final long acknowledge = begin.acknowledge();
                final int maximum = begin.maximum();
                final long traceId = begin.traceId();
                final long authorization = begin.authorization();
                final long affinity = begin.affinity();
                assert acknowledge <= sequence;
                assert sequence >= replySeq;
                assert acknowledge <= replyAck;
                replySeq = sequence;
                replyAck = acknowledge;
                assert replyAck == replySeq;
                assert maximum == 0;
                boolean handshakeHashOK = false;
                final OctetsFW extension = begin.extension();
                if (extension.sizeof() != 0)
                {
                    // TODO: need lightweight approach (start)
                    final HttpBeginExFW httpBeginEx = extension.get(httpBeginExRO::wrap);
                    final Map<String, String> headers = new LinkedHashMap<>();
                    httpBeginEx.headers().forEach(header ->
                    {
                        final String name = header.name().asString();
                        final String value = header.value().asString();
                        headers.merge(name, value, (v1, v2) -> String.format("%s, %s", v1, v2));
                    });
                    final String status = headers.get(":status");
                    final String upgrade = headers.get("upgrade");
                    final String hash = headers.get("sec-websocket-accept");
                    final String protocol = headers.get("sec-websocket-protocol");
                    // TODO: need lightweight approach (end)
                    if (WEBSOCKET_STATUS.equals(status) &&
                        WEBSOCKET_UPGRADE.equals(upgrade) &&
                        Objects.equals(this.protocol, protocol))
                    {
                        sha1.reset();
                        sha1.update(key.getBytes(US_ASCII));
                        final byte[] digest = sha1.digest(HANDSHAKE_GUID);
                        final Encoder encoder = Base64.getEncoder();
                        final String handshakeHash = new String(encoder.encode(digest), US_ASCII);
                        handshakeHashOK = handshakeHash.equals(hash);
                    }
                }
                if (handshakeHashOK)
                {
                    doAppBegin(maximum, traceId, authorization, affinity);
                }
                else
                {
                    doAppReset(traceId, authorization);
                }
            }
final String hash = headers.get("sec-websocket-accept");
final String protocol = headers.get("sec-websocket-protocol");
// TODO: need lightweight approach (end)
if (WEBSOCKET_STATUS.equals(status) &&
WEBSOCKET_UPGRADE.equals(upgrade) &&
httpBeginEx.headers().forEach(header ->
{
final String name = header.name().asString();
final String value = header.value().asString();
headers.merge(name, value, (v1, v2) -> String.format("%s, %s", v1, v2));
});
final String status = headers.get(":status");
final String upgrade = headers.get("upgrade");
final String hash = headers.get("sec-websocket-accept");
final String protocol = headers.get("sec-websocket-protocol");
// TODO: need lightweight approach (end)
if (WEBSOCKET_STATUS.equals(status) &&
WEBSOCKET_UPGRADE.equals(upgrade) &&
Objects.equals(this.protocol, protocol))
{
sha1.reset();
sha1.update(key.getBytes(US_ASCII));
final byte[] digest = sha1.digest(HANDSHAKE_GUID);
final Encoder encoder = Base64.getEncoder();
final String handshakeHash = new String(encoder.encode(digest), US_ASCII);
handshakeHashOK = handshakeHash.equals(hash);
replyAck = acknowledge;
assert replyAck == replySeq;
assert maximum == 0;
boolean handshakeHashOK = false;
final OctetsFW extension = begin.extension();
if (extension.sizeof() != 0)
{
// TODO: need lightweight approach (start)
final HttpBeginExFW httpBeginEx = extension.get(httpBeginExRO::wrap);
final Map<String, String> headers = new LinkedHashMap<>();
httpBeginEx.headers().forEach(header ->
{
final String name = header.name().asString();
final String value = header.value().asString();
headers.merge(name, value, (v1, v2) -> String.format("%s, %s", v1, v2));
});
final String status = headers.get(":status");
final String upgrade = headers.get("upgrade");
final String hash = headers.get("sec-websocket-accept");
final String protocol = headers.get("sec-websocket-protocol");
// TODO: need lightweight approach (end)
if (WEBSOCKET_STATUS.equals(status) &&
WEBSOCKET_UPGRADE.equals(upgrade) &&
Objects.equals(this.protocol, protocol))
{
sha1.reset();
sha1.update(key.getBytes(US_ASCII));
final byte[] digest = sha1.digest(HANDSHAKE_GUID);
final Encoder encoder = Base64.getEncoder();
final String handshakeHash = new String(encoder.encode(digest), US_ASCII);
handshakeHashOK = handshakeHash.equals(hash);
}
}
if (handshakeHashOK)
{
doAppBegin(maximum, traceId, authorization, affinity);
}
else
{
doAppReset(traceId, authorization);
}