// 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); }
// Prepare the request to send to the remote endpoint private IHttpRequest BuildRequest(HttpRequest requestIn, string toHostname) { var requestOut = new HttpClient.HttpRequest(); // Forward HTTP request headers foreach (var header in requestIn.Headers) { if (ExcludedRequestHeaders.Contains(header.Key.ToLowerInvariant())) { this.log.Debug("Ignoring request header", () => new { header.Key, header.Value }); continue; } this.log.Debug("Adding request header", () => new { header.Key, header.Value }); foreach (var value in header.Value) { requestOut.AddHeader(header.Key, value); } } var url = toHostname + requestIn.Path.Value + requestIn.QueryString; this.log.Debug("URL", () => new { url }); requestOut.SetUriFromString(url); // Forward request payload var method = requestIn.Method.ToUpperInvariant(); if (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); }