public StreamConnection performUpgrade() throws IOException {

    // Upgrade the connection
    // Set the upgraded flag already to prevent new requests after this one
    if (allAreSet(state, UPGRADED | CLOSE_REQ | CLOSED)) {
      throw new IOException(UndertowClientMessages.MESSAGES.connectionClosed());
    }
    state |= UPGRADED;
    return connection;
  }