Exemple #1
0
        private async Task <HttpStatusCode> Post(string url, Object o, string operation)
        {
            var request = new HttpRequestMessage(HttpMethod.Post, UnleashURLs.FetchTogglesUri);

            UnleashConfig.SetRequestProperties(request.Headers, _unleashConfig);
            request.Headers.Add("Cache-Control", "no-cache"); //  CacheControl.NoCache = true;
            request.Content = new StringContent(JsonConvert.SerializeObject(o), Encoding.UTF8, "application/json");

            var result = await HttpClient.SendAsync(request);

            if (!result.IsSuccessStatusCode)
            {
                Logger.WarnFormat("failed to {Operation}: statuscode {StatusCode}", operation, result.StatusCode);
            }
            return(result.StatusCode);
        }
Exemple #2
0
        public async Task <FeatureToggleResponse> FetchToggles()
        {
            var request = new HttpRequestMessage(HttpMethod.Get, UnleashURLs.FetchTogglesUri);

            if (!string.IsNullOrEmpty(_etag))
            {
                request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue(_etag));
            }
            //useCache(true)
            UnleashConfig.SetRequestProperties(request.Headers, _unleashConfig);

            var result = await HttpClient.SendAsync(request);

            return(await(result.IsSuccessStatusCode ?
                         GetToggleResponse(result) :
                         Task.FromResult(FeatureToggleResponse.NotChanged())));
        }
Exemple #3
0
        public void should_add_custom_headers_to_connection_if_present()
        {
            string unleashAPI  = "http://unleash.org";
            string headerName  = "UNLEASH-CUSTOM-TEST-HEADER";
            string headerValue = "Some value";

            UnleashConfig unleashConfig = UnleashConfig.TheBuilder()
                                          .AppName("my-app")
                                          .InstanceId("my-instance-1")
                                          .UnleashAPI(unleashAPI)
                                          .CustomHttpHeader(headerName, headerValue)
                                          .Build();

            var someUrl = new Uri(unleashAPI + "/some/arbitrary/path");
            var request = new HttpRequestMessage(HttpMethod.Get, someUrl);

            UnleashConfig.SetRequestProperties(request.Headers, unleashConfig);

            Assert.Single(request.Headers.GetValues(headerName));
            Assert.Equal(headerValue, request.Headers.GetValues(headerName).First());
        }
Exemple #4
0
        public void should_add_app_name_and_instance_id_and_user_agent_to_connection() //throws IOException
        {
            string appName    = "my-app";
            string instanceId = "my-instance-1";
            string unleashAPI = "http://unleash.org";

            var unleashConfig = UnleashConfig.TheBuilder()
                                .AppName(appName)
                                .InstanceId(instanceId)
                                .UnleashAPI(unleashAPI)
                                .Build();

            var someUrl = new Uri(unleashAPI + "/some/arbitrary/path");
            var request = new HttpRequestMessage(HttpMethod.Get, someUrl);

            UnleashConfig.SetRequestProperties(request.Headers, unleashConfig);

            Assert.Single(request.Headers.GetValues(UnleashConfig.UNLEASH_APP_NAME_HEADER));
            Assert.Equal(appName, request.Headers.GetValues(UnleashConfig.UNLEASH_APP_NAME_HEADER).First());
            Assert.Single(request.Headers.GetValues(UnleashConfig.UNLEASH_INSTANCE_ID_HEADER));
            Assert.Equal(instanceId, request.Headers.GetValues(UnleashConfig.UNLEASH_INSTANCE_ID_HEADER).First());
            Assert.Equal(appName, request.Headers.GetValues("User-Agent").First());
        }