anchor.diff:      WSUpgradeHeaders = [{<<"sec-websocket-protocol">>, <<"xmpp">>}],
       StreamRef = gun:ws_upgrade(ConnPid, Resource, WSUpgradeHeaders,
                                  #{protocols => [{<<"xmpp">>, gun_ws_h}]}),
  -    wait_for_ws_upgrade(ConnPid, StreamRef),
  +    Timeout = get_option(ws_upgrade_timeout, Args, 5000),
  +    wait_for_ws_upgrade(ConnPid, StreamRef, Timeout),
       ParserOpts = case LegacyWS of
                        true -> [];
                        _ -> [{infinite_stream, true}, {autoreset, true}]
  
positive.code:                 legacy_ws = LegacyWS,
                  event_client = EventClient}}.
  
  wait_for_ws_upgrade(ConnPid, StreamRef) ->
      receive
          {gun_upgrade, ConnPid, StreamRef, [<<"websocket">>], _} ->
              ok;
  
negative.code:         {gun_error, ConnPid, _StreamRef, Reason} ->
              exit({ws_upgrade_failed, Reason})
      after %% More clauses here as needed.
            Timeout ->
              exit(ws_upgrade_timeout)
      end.
  
  