public WebSocketsTransport()

in src/Microsoft.Azure.SignalR.Common/ServiceConnections/Internal/WebSocketsTransport.cs [50:106]


    public WebSocketsTransport(WebSocketConnectionOptions connectionOptions,
                               ILoggerFactory loggerFactory,
                               IAccessTokenProvider accessTokenProvider)
    {
        _logger = (loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory))).CreateLogger<WebSocketsTransport>();
        _webSocket = new ClientWebSocket();

        // Issue in ClientWebSocket prevents user-agent being set - https://github.com/dotnet/corefx/issues/26627
        //_webSocket.Options.SetRequestHeader("User-Agent", Constants.UserAgentHeader.ToString());

        if (connectionOptions != null)
        {
            if (connectionOptions.Headers != null)
            {
                foreach (var header in connectionOptions.Headers)
                {
                    _webSocket.Options.SetRequestHeader(header.Key, header.Value);
                }
            }

            if (connectionOptions.Cookies != null)
            {
                _webSocket.Options.Cookies = connectionOptions.Cookies;
            }

            if (connectionOptions.ClientCertificates != null)
            {
                _webSocket.Options.ClientCertificates.AddRange(connectionOptions.ClientCertificates);
            }

            if (connectionOptions.Credentials != null)
            {
                _webSocket.Options.Credentials = connectionOptions.Credentials;
            }

            if (connectionOptions.Proxy != null)
            {
                _webSocket.Options.Proxy = connectionOptions.Proxy;
            }

            if (connectionOptions.UseDefaultCredentials != null)
            {
                _webSocket.Options.UseDefaultCredentials = connectionOptions.UseDefaultCredentials.Value;
            }

            connectionOptions.WebSocketConfiguration?.Invoke(_webSocket.Options);

            _closeTimeout = connectionOptions.CloseTimeout;
        }

        // Set this header so the server auth middleware will set an Unauthorized instead of Redirect status code
        // See: https://github.com/aspnet/Security/blob/ff9f145a8e89c9756ea12ff10c6d47f2f7eb345f/src/Microsoft.AspNetCore.Authentication.Cookies/Events/CookieAuthenticationEvents.cs#L42
        _webSocket.Options.SetRequestHeader("X-Requested-With", "XMLHttpRequest");

        // Ignore the HttpConnectionOptions access token provider. We were given an updated delegate from the HttpConnection.
        _accessTokenProvider = accessTokenProvider;
    }