• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
No results for ""
EXPAND ALL

EDIT ON GITHUB

Web proxy configuration

Read time: 3 minutes
Last edited: May 20, 2022

Overview

This topic explains how to configure an SDK to connect to LaunchDarkly through a web proxy. This feature is available for both client-side and server-side SDKs.

Connecting to LaunchDarkly through a web proxy is not related to using LaunchDarkly's Relay Proxy. To learn about LaunchDarkly's Relay Proxy, read The Relay Proxy.

Connecting though a web proxy

If your organization requires that you use a web proxy to connect to external resources, you must configure your LaunchDarkly SDKs to connect through the proxy instead of connecting to LaunchDarkly directly.

Some proxies require authentication with a username and password, or with custom headers. Instructions on how to configure the SDK to send these parameters are in the SDK-specific sections.

In the following examples, the web proxy's hostname is "my-proxy-host" and it uses port 8080. Substitute the appropriate values for your proxy. Details about each SDK's configuration are available in the SDK-specific sections below:

  • Client-side SDKs
  • Server-side SDKs
Using a web proxy with mobile SDKs

Android, Flutter, iOS, and React Native support using a web proxy through their device operating systems (OS). You can use their onboard OS settings to configure a web proxy.

Client-side SDKs

This feature is available in the following client-side SDKs:

.NET (client-side)

Expand .NET (client-side) code sample

To configure the client-side .NET SDK to connect to LaunchDarkly through a web proxy:

var handler = new System.Net.Http.HttpClientHandler();
handler.Proxy = new System.Net.WebProxy("http://my-proxy-host:8080");
var config = Configuration.Builder("mobile-key")
.HttpMessageHandler(handler)
.Build();

To configure the client-side .NET SDK to connect to LaunchDarkly through a web proxy with authentication:

var handler = new System.Net.Http.HttpClientHandler();
var proxy = new System.Net.WebProxy("http://my-proxy-host:8080");
var credentials = new System.Net.CredentialCache();
credentials.Add(proxy.Address, "Basic",
new NetworkCredential("username", "password"));
proxy.Credentials = credentials;
handler.Proxy = proxy;
var config = Configuration.Builder("mobile-key")
.HttpMessageHandler(handler)
.Build();

C/C++ (client-side)

Expand C/C++ (client-side) code sample

To configure the C/C++ SDK to connect to LaunchDarkly through a web proxy:

struct LDConfig *config = LDConfigNew("YOUR_MOBILE_KEY");
LDConfigSetProxyURI(config, "https://web-proxy.domain.com:8080");

To configure the client-side C/C++ SDK to connect to LaunchDarkly through a web proxy with authentication:

struct LDConfig *config = LDConfigNew("YOUR_MOBILE_KEY");
LDConfigSetProxyURI(config, "https://username:password@web-proxy.domain.com:8080");

Server-side SDKs

.NET (server-side)

Expand .NET (server-side) code sample

To configure the server-side .NET SDK to connect to LaunchDarkly through a web proxy:

var proxy = new System.Net.WebProxy("http://my-proxy-host:8080");
var config = Configuration.Builder("sdk-key")
.Http(Components.HttpConfiguration().Proxy(proxy))
.Build();

To configure the server-side .NET SDK to connect to LaunchDarkly through a web proxy with authentication:

var proxy = new System.Net.WebProxy("http://my-proxy-host:8080");
var credentials = new System.Net.CredentialCache();
credentials.Add(proxy.Address, "Basic",
new NetworkCredential("username", "password"));
proxy.Credentials = credentials;
var config = Configuration.Builder("sdk-key")
.Http(Components.HttpConfiguration().Proxy(proxy))
.Build();

Apex

Expand Apex code sample

The Apex bridge that provides and retrieves flag values is written in Go, and uses the default Go networking mechanisms. 

Go's standard HTTP library recognizes the environment variables HTTP_PROXY and HTTPS_PROXY. If you set these variables, the SDK will connect through a web proxy at the URL you provide. Because the LaunchDarkly services have https: URLs, you use HTTPS_PROXY. If you are connecting to services at an insecure http: URL use HTTP_PROXY instead.

Here is an example:

export HTTPS_PROXY=https://my-proxy-host:8080

Go

Expand Go code sample

There are two ways to specify proxy server parameters in the Go SDK.

Go's standard HTTP library recognizes the environment variables HTTP_PROXY and HTTPS_PROXY. If you set these variables, the SDK will connect through a web proxy at the URL you provide. Because the LaunchDarkly services have https: URLs, you use HTTPS_PROXY. If you are connecting to services at an insecure http: URL, such as a Relay Proxy instance, use HTTP_PROXY instead.

Here is an example:

export HTTPS_PROXY=https://my-proxy-host:8080

You can also specify a proxy programmatically through the SDK configuration:

import (
ld "gopkg.in/launchdarkly/go-server-sdk.v5"
"gopkg.in/launchdarkly/go-server-sdk.v5/ldcomponents"
)
var config ld.Config
config.HTTP = ldcomponents.HTTPConfiguration().
ProxyURL("https://my-proxy-host:8080")

Java

Expand Java code sample

To configure the Java SDK to connect to LaunchDarkly through a web proxy:

LDConfig config = new LDConfig.Builder()
.http(Components.httpConfiguration().proxyHostAndPort("my-proxy-host", 8080))
.build();

To configure the Java SDK to connect to LaunchDarkly through a web proxy with authentication:

LDConfig config = new LDConfig.Builder()
.http(Components.httpConfiguration()
.proxyHostAndPort("my-proxy-host", 8080)
.proxyAuth(Components.httpBasicAuthentication("username", "password"))
.build();

Node.js (server-side)

Expand Node.js (server-side) code sample

To configure the server-side Node.js SDK to connect to LaunchDarkly through a web proxy:

const options = {
proxyHost: 'your-proxy-host',
proxyPort: 8080
};

To configure the server-side Node.js SDK to connect to LaunchDarkly through a web proxy with authentication:

const options = {
proxyHost: 'my-proxy-host',
proxyPort: 8080,
proxyAuth: 'username:password'
};

Python

Expand Python code sample

There are two ways to specify proxy server parameters in the Python SDK.

Python's standard HTTP library recognizes the environment variables HTTP_PROXY and HTTPS_PROXY. If you set these variables, the SDK will connect through a web proxy at the URL you provide. Because the LaunchDarkly services have https: URLs, you use HTTPS_PROXY. If you are connecting to services at an insecure http: URL, such as a Relay Proxy instance, use HTTP_PROXY instead.

How to set the HTTPS_PROXY environment variable on Mac/Linux and Windows systems:

export HTTPS_PROXY=https://my-proxy-host:8080

Or it can be set from within Python:

os.environ["https_proxy"] = "https://my-proxy-host:8080"

Ruby

Expand Ruby code sample

There are two ways to specify proxy server parameters in the Ruby SDK.

Ruby's standard HTTP library recognizes the environment variables HTTP_PROXY and HTTPS_PROXY. If you set these variables, the SDK will connect through a web proxy at the URL you provide. Because the LaunchDarkly services have https: URLs, you use HTTPS_PROXY. If you are connecting to services at an insecure http: URL, such as a Relay Proxy instance, use HTTP_PROXY instead.

To configure the Ruby SDK to connect to LaunchDarkly through a web proxy:

export HTTPS_PROXY=https://my-proxy-host:8080

Or it can be set from within Ruby:

ENV['HTTPS_PROXY'] = 'https://my-proxy-host:8080'