anchor.diff:          {gun_error, ConnPid, _StreamRef, Reason} ->
               exit({ws_upgrade_failed, Reason})
       after %% More clauses here as needed.
  -          1000 ->
  +          Timeout ->
               exit(ws_upgrade_timeout)
       end.
   
  
positive.code:                 legacy_ws = LegacyWS,
                  event_client = EventClient}}.
  
  wait_for_ws_upgrade(ConnPid, StreamRef) ->
      receive
          {gun_upgrade, ConnPid, StreamRef, [<<"websocket">>], _} ->
              ok;
  
negative.code:     WSUpgradeHeaders = [{<<"sec-websocket-protocol">>, <<"xmpp">>}],
      StreamRef = gun:ws_upgrade(ConnPid, Resource, WSUpgradeHeaders,
                                 #{protocols => [{<<"xmpp">>, gun_ws_h}]}),
      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}]
  