Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 5ce1ca5

Browse files
LaunchDarklyReleaseBoteli-darklyLaunchDarklyReleaseBotaengelbergantonmos
authored
prepare 6.2.0 release (#309)
## [6.2.0] - 2023-06-12 ### Added: - Custom headers can now be added to all HTTP requests with `Components.httpConfiguration().addCustomHeader`. --------- Co-authored-by: Eli Bishop <[email protected]> Co-authored-by: LaunchDarklyReleaseBot <[email protected]> Co-authored-by: Alex Engelberg <[email protected]> Co-authored-by: Anton Mostovoy <[email protected]> Co-authored-by: LaunchDarklyCI <[email protected]> Co-authored-by: LaunchDarklyCI <[email protected]> Co-authored-by: Gavin Whelan <[email protected]> Co-authored-by: ssrm <[email protected]> Co-authored-by: Harpo Roeder <[email protected]> Co-authored-by: Ben Woskow <[email protected]> Co-authored-by: Elliot <[email protected]> Co-authored-by: Robert J. Neal <[email protected]> Co-authored-by: Robert J. Neal <[email protected]> Co-authored-by: Sam Stokes <[email protected]> Co-authored-by: Ember Stevens <[email protected]> Co-authored-by: ember-stevens <[email protected]> Co-authored-by: Alex Engelberg <[email protected]> Co-authored-by: Louis Chan <[email protected]> Co-authored-by: Louis Chan <[email protected]> Co-authored-by: Todd Anderson <[email protected]> Co-authored-by: tanderson-ld <[email protected]> Co-authored-by: Matthew M. Keeler <[email protected]>
1 parent 13d01ff commit 5ce1ca5

File tree

4 files changed

+67
-22
lines changed

4 files changed

+67
-22
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
## LaunchDarkly overview
77

8-
[LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves over 100 billion feature flags daily to help teams build better software, faster. [Get started](https://docs.launchdarkly.com/home/getting-started) using LaunchDarkly today!
8+
[LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves trillions of feature flags daily to help teams build better software, faster. [Get started](https://docs.launchdarkly.com/home/getting-started) using LaunchDarkly today!
99

1010
[![Twitter Follow](https://img.shields.io/twitter/follow/launchdarkly.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/intent/follow?screen_name=launchdarkly)
1111

@@ -54,7 +54,7 @@ Unlike some other languages, in Java the DNS caching behavior is controlled by t
5454

5555
## Learn more
5656

57-
Check out our [documentation](https://docs.launchdarkly.com) for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the [complete reference guide for this SDK](https://docs.launchdarkly.com/docs/java-sdk-reference) or our [code-generated API documentation](https://launchdarkly.github.io/java-server-sdk/).
57+
Read our [documentation](https://docs.launchdarkly.com) for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the [complete reference guide for this SDK](https://docs.launchdarkly.com/docs/java-sdk-reference) or our [code-generated API documentation](https://launchdarkly.github.io/java-server-sdk/).
5858

5959
## Testing
6060

src/main/java/com/launchdarkly/sdk/server/ComponentsImpl.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import java.net.Proxy;
4040
import java.net.URI;
4141
import java.time.Duration;
42+
import java.util.HashMap;
43+
import java.util.Map;
4244
import java.util.concurrent.CompletableFuture;
4345
import java.util.concurrent.Future;
4446

@@ -325,10 +327,12 @@ static final class HttpConfigurationBuilderImpl extends HttpConfigurationBuilder
325327
@Override
326328
public HttpConfiguration build(ClientContext clientContext) {
327329
LDLogger logger = clientContext.getBaseLogger();
330+
328331
// Build the default headers
329-
ImmutableMap.Builder<String, String> headers = ImmutableMap.builder();
332+
Map<String, String> headers = new HashMap<>();
330333
headers.put("Authorization", clientContext.getSdkKey());
331334
headers.put("User-Agent", "JavaClient/" + Version.SDK_VERSION);
335+
332336
if (clientContext.getApplicationInfo() != null) {
333337
String tagHeader = Util.applicationTagHeader(clientContext.getApplicationInfo(), logger);
334338
if (!tagHeader.isEmpty()) {
@@ -337,14 +341,18 @@ public HttpConfiguration build(ClientContext clientContext) {
337341
}
338342
if (wrapperName != null) {
339343
String wrapperId = wrapperVersion == null ? wrapperName : (wrapperName + "/" + wrapperVersion);
340-
headers.put("X-LaunchDarkly-Wrapper", wrapperId);
344+
headers.put("X-LaunchDarkly-Wrapper", wrapperId);
345+
}
346+
347+
if (!customHeaders.isEmpty()) {
348+
headers.putAll(customHeaders);
341349
}
342350

343351
Proxy proxy = proxyHost == null ? null : new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
344352

345353
return new HttpConfiguration(
346354
connectTimeout,
347-
headers.build(),
355+
headers,
348356
proxy,
349357
proxyAuth,
350358
socketFactory,

src/main/java/com/launchdarkly/sdk/server/integrations/HttpConfigurationBuilder.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.launchdarkly.sdk.server.subsystems.HttpConfiguration;
77

88
import java.time.Duration;
9+
import java.util.HashMap;
10+
import java.util.Map;
911

1012
import javax.net.SocketFactory;
1113
import javax.net.ssl.SSLSocketFactory;
@@ -45,6 +47,7 @@ public abstract class HttpConfigurationBuilder implements ComponentConfigurer<Ht
4547
protected Duration connectTimeout = DEFAULT_CONNECT_TIMEOUT;
4648
protected HttpAuthentication proxyAuth;
4749
protected String proxyHost;
50+
protected Map<String, String> customHeaders = new HashMap<>();
4851
protected int proxyPort;
4952
protected Duration socketTimeout = DEFAULT_SOCKET_TIMEOUT;
5053
protected SocketFactory socketFactory;
@@ -137,6 +140,21 @@ public HttpConfigurationBuilder sslSocketFactory(SSLSocketFactory sslSocketFacto
137140
return this;
138141
}
139142

143+
/**
144+
* Specifies a custom HTTP header that should be added to all SDK requests.
145+
* <p>
146+
* This may be helpful if you are using a gateway or proxy server that requires a specific header in requests. You
147+
* may add any number of headers.
148+
*
149+
* @param headerName standard HTTP header
150+
* @param headerValue standard HTTP value
151+
* @return the builder
152+
*/
153+
public HttpConfigurationBuilder addCustomHeader(String headerName, String headerValue) {
154+
this.customHeaders.put(headerName, headerValue);
155+
return this;
156+
}
157+
140158
/**
141159
* For use by wrapper libraries to set an identifying name for the wrapper being used. This will be included in a
142160
* header during requests to the LaunchDarkly servers to allow recording metrics on the usage of

src/test/java/com/launchdarkly/sdk/server/integrations/HttpConfigurationBuilderTest.java

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
public class HttpConfigurationBuilderTest {
3535
private static final String SDK_KEY = "sdk-key";
3636
private static final ClientContext BASIC_CONTEXT = new ClientContext(SDK_KEY);
37-
37+
3838
private static ImmutableMap.Builder<String, String> buildBasicHeaders() {
3939
return ImmutableMap.<String, String>builder()
4040
.put("Authorization", SDK_KEY)
4141
.put("User-Agent", "JavaClient/" + getSdkVersion());
4242
}
43-
43+
4444
@Test
4545
public void testDefaults() {
4646
HttpConfiguration hc = Components.httpConfiguration().build(BASIC_CONTEXT);
@@ -54,6 +54,25 @@ public void testDefaults() {
5454
assertEquals(buildBasicHeaders().build(), ImmutableMap.copyOf(hc.getDefaultHeaders()));
5555
}
5656

57+
@Test
58+
public void testCanSetCustomHeaders() {
59+
HttpConfiguration hc = Components.httpConfiguration()
60+
.addCustomHeader("X-LaunchDarkly-Test-Label", "my-cool-label")
61+
.addCustomHeader("X-Header-Message", "Java FTW")
62+
.addCustomHeader("Authorization", "I can override this")
63+
.addCustomHeader("User-Agent", "This too")
64+
.build(BASIC_CONTEXT);
65+
66+
ImmutableMap<String, String> expectedHeaders = ImmutableMap.<String, String>builder()
67+
.put("X-LaunchDarkly-Test-Label", "my-cool-label")
68+
.put("X-Header-Message", "Java FTW")
69+
.put("Authorization", "I can override this")
70+
.put("User-Agent", "This too")
71+
.build();
72+
73+
assertEquals(expectedHeaders, ImmutableMap.copyOf(hc.getDefaultHeaders()));
74+
}
75+
5776
@Test
5877
public void testConnectTimeout() {
5978
HttpConfiguration hc = Components.httpConfiguration()
@@ -101,7 +120,7 @@ public void testSocketTimeout() {
101120
.build(BASIC_CONTEXT);
102121
assertEquals(DEFAULT_SOCKET_TIMEOUT, hc2.getSocketTimeout());
103122
}
104-
123+
105124
@Test
106125
public void testSocketFactory() {
107126
SocketFactory sf = new StubSocketFactory();
@@ -110,7 +129,7 @@ public void testSocketFactory() {
110129
.build(BASIC_CONTEXT);
111130
assertSame(sf, hc.getSocketFactory());
112131
}
113-
132+
114133
@Test
115134
public void testSslOptions() {
116135
SSLSocketFactory sf = new StubSSLSocketFactory();
@@ -146,22 +165,22 @@ public void testApplicationTags() {
146165
.build(contextWithTags);
147166
assertEquals("application-id/authentication-service application-version/1.0.0", ImmutableMap.copyOf(hc.getDefaultHeaders()).get("X-LaunchDarkly-Tags"));
148167
}
149-
168+
150169
public static class StubSocketFactory extends SocketFactory {
151170
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
152171
throws IOException {
153172
return null;
154173
}
155-
174+
156175
public Socket createSocket(String host, int port, InetAddress localHost, int localPort)
157176
throws IOException, UnknownHostException {
158177
return null;
159178
}
160-
179+
161180
public Socket createSocket(InetAddress host, int port) throws IOException {
162181
return null;
163182
}
164-
183+
165184
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
166185
return null;
167186
}
@@ -176,40 +195,40 @@ public Socket createSocket(InetAddress address, int port, InetAddress localAddre
176195
throws IOException {
177196
return null;
178197
}
179-
198+
180199
public Socket createSocket(String host, int port, InetAddress localHost, int localPort)
181200
throws IOException, UnknownHostException {
182201
return null;
183202
}
184-
203+
185204
public Socket createSocket(InetAddress host, int port) throws IOException {
186205
return null;
187206
}
188-
207+
189208
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
190209
return null;
191210
}
192-
211+
193212
public String[] getSupportedCipherSuites() {
194213
return null;
195214
}
196-
215+
197216
public String[] getDefaultCipherSuites() {
198217
return null;
199218
}
200-
219+
201220
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
202221
return null;
203222
}
204223
}
205-
224+
206225
public static class StubX509TrustManager implements X509TrustManager {
207226
public X509Certificate[] getAcceptedIssuers() {
208227
return null;
209228
}
210-
229+
211230
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
212-
231+
213232
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
214233
}
215234
}

0 commit comments

Comments
 (0)