public IActionResult Index() { var result = featuresManager.FeaturesOld.Keys; var currentFeature = featuresManager.GetFeatureFromCookieOrHeader(Request); ViewBag.Features = result.Select(c => c); ViewBag.CurrentFeature = currentFeature; return(View()); }
public void GetFeatureFromCookieOrHeader_GetsCorrectFeatureFromHeader() { // Arrange var httpContext = new DefaultHttpContext(); var randomfeaturename = Guid.NewGuid().ToString(); httpContext.Request.Headers.Add(FeaturesManager.HTTPHEADER_FEATURE, randomfeaturename); // Act var result = target.GetFeatureFromCookieOrHeader(httpContext.Request); // Assert Assert.Equal(randomfeaturename, result.feature); Assert.Equal(FeatureAvailability.Header, result.featureAvailability); }
// Prepare the request to send to the remote endpoint private IHttpRequest BuildRequest(HttpRequest requestIn) { var requestOut = new HttpClient.HttpRequest(); // Forward HTTP request headers foreach (var header in requestIn.Headers) { if (ExcludedRequestHeaders.Contains(header.Key.ToLowerInvariant())) { this.log.LogDebug("Ignoring request header", new { header.Key, header.Value }); continue; } this.log.LogDebug("Adding request header", new { header.Key, header.Value }); foreach (var value in header.Value) { requestOut.AddHeader(header.Key, value); } } FeatureAvailability featureAvailability; (feature, featureAvailability) = featuresManager.GetFeatureFromCookieOrHeader(requestIn); if (featureAvailability == FeatureAvailability.Cookie) { // feature available in cookie, but not as http header. Add to outgoing http headers: requestOut.AddHeader(FeaturesManager.HTTPHEADER_FEATURE, feature); } var urls = featuresManager.GetUrlFromFeatureConfiguration(feature, requestIn); fromSchemeHostname = urls?.fromSchemeHostname; fromUrl = urls?.fromUrl; requestOut.SetUriFromString(urls?.toUrl ?? requestIn.GetEncodedUrl()); // Forward request payload var method = requestIn.Method.ToUpperInvariant(); if (Microsoft.Azure.IoTSolutions.ReverseProxy.HttpClient.HttpClient.MethodsWithPayload.Contains(method)) { requestOut.SetContent(this.GetRequestPayload(requestIn), requestIn.ContentType); } // Allow error codes without throwing an exception requestOut.Options.EnsureSuccess = false; // The HTTP client uses cert. pinning, allowing self-signed certs requestOut.Options.AllowInsecureSslServer = true; return(requestOut); }