Esempio n. 1
0
        public RpcClient(Uri baseUrl, AuthenticationHeaderValue authHeaderValue = null,
                         JsonSerializerSettings jsonSerializerSettings          = null, HttpClientHandler httpClientHandler = null, ILog log = null)
        {
            _baseUrl = baseUrl;

            if (authHeaderValue == null)
            {
                authHeaderValue = UserAuthentication.FromUri(baseUrl)?.GetBasicAuthenticationHeaderValue();
            }

            _authHeaderValue = authHeaderValue;
            if (jsonSerializerSettings == null)
            {
                jsonSerializerSettings = DefaultJsonSerializerSettingsFactory.BuildDefaultJsonSerializerSettings();
            }
            _jsonSerializerSettings = jsonSerializerSettings;
            _httpClientHandler      = httpClientHandler;
            _log = log;
            CreateNewHttpClient();
        }
Esempio n. 2
0
        public RpcClient(Uri baseUrl, HttpClient httpClient, AuthenticationHeaderValue authHeaderValue = null,
                         JsonSerializerSettings jsonSerializerSettings = null, ILog log = null)
        {
            _baseUrl = baseUrl;

            if (authHeaderValue == null)
            {
                authHeaderValue = UserAuthentication.FromUri(baseUrl)?.GetBasicAuthenticationHeaderValue();
            }

            _authHeaderValue = authHeaderValue;
            if (jsonSerializerSettings == null)
            {
                jsonSerializerSettings = DefaultJsonSerializerSettingsFactory.BuildDefaultJsonSerializerSettings();
            }
            _jsonSerializerSettings = jsonSerializerSettings;
            _log = log;
            InitialiseHttpClient(httpClient);
            _httpClient        = httpClient;
            _rotateHttpClients = false;
        }
        public static UserAuthentication FromUri(Uri uri)
        {
            if (string.IsNullOrEmpty(uri.UserInfo))
            {
                return(null);
            }

            var userInfo = uri.UserInfo?.Split(':');
            UserAuthentication userAuthentication = null;

            if (userInfo != null)
            {
                userAuthentication          = new UserAuthentication();
                userAuthentication.UserName = userInfo[0];
                if (userInfo.Length > 1)
                {
                    userAuthentication.Password = userInfo[1];
                }
            }

            return(userAuthentication);
        }