Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.13.0 #104

Merged
merged 179 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
b87b6ed
Add support for TLS 1.2 on API 16+
farhanjkhan May 8, 2018
2931d51
Add back final keyword
farhanjkhan May 9, 2018
5bab855
Bumping the minSdkVersion from 15 to 16
farhanjkhan May 9, 2018
f853d84
Merge branch 'next-release' into feature/tls_1_2
arun251 Aug 14, 2018
024a75b
Merge pull request #64 from launchdarkly/feature/tls_1_2
arun251 Aug 14, 2018
ff65ca3
Merge branch 'master' into next-release
arun251 Sep 12, 2018
44eed4a
Circle CI 2.0
nejifresh Sep 25, 2018
ba1fe52
Created new branch for multi-environment sdk feature
torchhound Oct 1, 2018
c47d2d5
Stub out new LDConfig and LDConfig.Builder code for multi-environment.
gavwhela Oct 1, 2018
73e4b98
Added overloaded init method in LDClient for creating secondary insta…
torchhound Oct 2, 2018
3962f10
Added getForMobileKey methods
torchhound Oct 2, 2018
c020ff9
Added LDClient init test for secondary environment, added exception t…
torchhound Oct 2, 2018
1956014
Move primary instance into general instances map. Begin on methods ef…
gavwhela Oct 2, 2018
cf10753
Removed incorrect LDClient test
torchhound Oct 2, 2018
a09191d
Fixed 1 failing test in LDClient, added multi-environment test file, …
torchhound Oct 2, 2018
e318b61
Removed unnecessary ListenableFuture in LDClient init, changed identi…
torchhound Oct 2, 2018
0fbe675
Added setOnlineStatus multi-environment changes
torchhound Oct 3, 2018
afe797a
Moved primaryEnvironmentName to LDConfig, simplifying by removing pri…
gavwhela Oct 6, 2018
babd1cd
Add back in constructor without environment to UserManager
gavwhela Oct 6, 2018
33fd8d7
Specialize HttpFeatureFlagFetcher to the environment, looks like User…
gavwhela Oct 6, 2018
eb93b8c
Added SharedPreferences migration strategy
Oct 6, 2018
43ded05
Merged UserManager changes
Oct 6, 2018
b595b6c
All tests pass, fixed migration strategy to conform to spec, fixed pr…
torchhound Oct 8, 2018
e8ac421
Update StreamUpdateProcessor construct to take an environment for the…
gavwhela Oct 9, 2018
441fa93
Fix issue with LDConfig mobileKeys hashmap creation.
gavwhela Oct 9, 2018
f0b68e6
Combine futures so LDClient init future waits on all online instances…
gavwhela Oct 10, 2018
1a039e1
Propagate IOException on closing instances to caller.
gavwhela Oct 10, 2018
baea3ff
Merge futures for identify call.
gavwhela Oct 10, 2018
fc665cf
Some changes from code review.
gavwhela Oct 11, 2018
783375d
Removed static from instanceId and now old SharedPreferences will onl…
Oct 11, 2018
f82c03f
Fixed instanceId
torchhound Oct 11, 2018
be1dd1c
Updates from PR review.
gavwhela Oct 17, 2018
f647f3b
Merge pull request #83 from launchdarkly/circlecimigrate
arun251 Oct 17, 2018
3dbab83
Merge branch 'master' into next-release
arun251 Oct 25, 2018
a8d4b53
Added version and flagVersion, if available
jamesthacker Nov 6, 2018
f2c456e
refactor(LDClient, LDConfig): changes for PR
torchhound Dec 12, 2018
9215b65
refactor(LDClient): changed isInternetConnected behavior for PR
torchhound Dec 12, 2018
5cce5b8
refactor(LDClient): removed async getForMobileKeys and wait seconds v…
torchhound Dec 12, 2018
f2d1343
Bugfix/timber cleanup (#92)
jamesthacker Jan 12, 2019
081ee16
Merge pull request #91 from launchdarkly/bugfix/ping-event-versions
gavwhela Jan 12, 2019
cac1e27
Fix crash when example app is backgrounded twice.
gwhelanLD Jan 14, 2019
ceaa85a
Merge pull request #93 from launchdarkly/bugfix/example-background-crash
torchhound Jan 15, 2019
84569fe
Merge remote-tracking branch 'remotes/origin/multi-environment' into …
gwhelanLD Jan 16, 2019
cd02ea3
Add security provider update mechanism using Google Play Services to
gwhelanLD Jan 22, 2019
6b135f4
Shared Preferences Fix for Multi Environment (#94)
torchhound Jan 22, 2019
55eef13
Fix edge cases in how multi-environment handles connection changes.
gwhelanLD Jan 22, 2019
562fd56
fix(UserManagerTest.java): incorrect number of arguments to UserManag…
Jan 22, 2019
9edb050
Remove line of testing code accidentally left in and refactor shared
gwhelanLD Jan 22, 2019
34c942a
Final fixes to store migration. Should be fairly future proof.
gwhelanLD Jan 22, 2019
fd0560c
Merge branch 'master' into next-release
gwhelanLD Jan 24, 2019
6ca1acd
Merge branch 'master' into next-release
gwhelanLD Jan 24, 2019
3b8faca
Merge branch 'master' into next-release
gwhelanLD Feb 4, 2019
964c5cd
Fix issue with primitive variation calls always returning null if fal…
gwhelanLD Feb 6, 2019
5fcd6b1
Remove CircleCI V1 config file. (#97)
gwhelanLD Feb 6, 2019
1f5eb1f
Remove getting/comparing versions as floats (#99)
gwhelanLD Feb 11, 2019
ae3791a
Include values in unknown summary events and compare values for (#100)
gwhelanLD Feb 11, 2019
a6061cf
simplify flag property deserialization
eli-darkly Feb 12, 2019
21677be
rm debugging
eli-darkly Feb 12, 2019
8d23b67
misc cleanup
eli-darkly Feb 12, 2019
86fb7f9
rm debugging
eli-darkly Feb 12, 2019
dc2d450
add eval reason data model classes
eli-darkly Feb 12, 2019
1b785e9
Merge branch 'next-release' into eb/ch31900/store-query-properties
eli-darkly Feb 12, 2019
2a76698
Merge branch 'eb/ch31900/store-query-properties' into eb/ch31891/eval…
eli-darkly Feb 12, 2019
18a488d
misc fixes
eli-darkly Feb 12, 2019
eb5a98f
serialize reason
eli-darkly Feb 12, 2019
eea98fc
Merge pull request #101 from launchdarkly/eb/ch31900/store-query-prop…
eli-darkly Feb 13, 2019
352eb42
add ability to receive evaluation reasons from LD
eli-darkly Feb 13, 2019
a82e02d
Merge pull request #102 from launchdarkly/eb/ch31891/eval-reasons
eli-darkly Feb 14, 2019
c544f75
Merge pull request #103 from launchdarkly/eb/ch31891/get-reasons
eli-darkly Feb 14, 2019
503cfcb
Changed shared preferences store system to user a single FlagStore
gwhelanLD Feb 14, 2019
213dd47
add methods to get value with explanation; refactor existing variatio…
eli-darkly Feb 15, 2019
bd6ad95
Abstract FlagStoreManager from FlagStore, new FlagStoreFactory class …
gwhelanLD Feb 15, 2019
8460f0c
Handle null case in allFlags, actually commit changes to UserManager.
gwhelanLD Feb 15, 2019
d7e5d64
Merge branch 'gw/ch29266/flagstore' into eb/ch31891/variation-detail
eli-darkly Feb 15, 2019
f565301
Hopefully fix edge cases in summary event reporting to pass testing.
gwhelanLD Feb 15, 2019
0b3d570
Hopefully fix edge cases in summary event reporting to pass testing.
gwhelanLD Feb 16, 2019
709e107
Simplify getFeaturesJsonObject as no longer using -1 as placeholder f…
gwhelanLD Feb 16, 2019
1804437
Make Flag non-mutable. Move GsonCache to gson package, move custom se…
gwhelanLD Feb 19, 2019
261d90c
Send summary event even if stored flag doesn't exist.
gwhelanLD Feb 21, 2019
f4fb467
Move sendSummaryEvent update code to UserSummaryEventSharedPreference…
gwhelanLD Feb 21, 2019
7489890
Update SharedPrefsFlagStore to hold StoreUpdatedListener in weak refe…
gwhelanLD Feb 22, 2019
5766828
Migration code for upcoming flagstore.
gwhelanLD Feb 22, 2019
57f645d
Remove couple of debug messages.
gwhelanLD Feb 22, 2019
aeec638
Handle todos.
gwhelanLD Feb 22, 2019
c654453
Revert to old String behavior for allFlags, initialize WeakReference …
gwhelanLD Feb 22, 2019
19a9401
Merge branch 'gw/ch29266/flagstore' into eb/ch31891/variation-detail
eli-darkly Feb 22, 2019
69c1c9b
Better implementation of EvaluationReason serialization type adapter.
gwhelanLD Feb 26, 2019
23fd36a
Revert "Better implementation of EvaluationReason serialization type
gwhelanLD Feb 26, 2019
becd7e5
Gw/ch29266/flagstore (#105)
gwhelanLD Feb 26, 2019
76f4650
Return json flags as JsonElement in allFlags map. (#106)
gwhelanLD Feb 26, 2019
c246a27
Merge branch 'next-release' into eb/ch31891/variation-detail
eli-darkly Feb 27, 2019
54ac5cf
Bump ok-http version to 3.9.1 (#107)
gwhelanLD Mar 1, 2019
8e36a32
fix annotations so eval reasons are serialized in events
eli-darkly Mar 2, 2019
85a5adf
Merge pull request #104 from launchdarkly/eb/ch31891/variation-detail
eli-darkly Mar 2, 2019
84ecc29
fix/expand doc comments for public methods
eli-darkly Mar 5, 2019
46948c0
typo
eli-darkly Mar 5, 2019
192e4da
typo
eli-darkly Mar 5, 2019
1a7f34b
Merge pull request #108 from launchdarkly/eb/ch33404/doc-comments
eli-darkly Mar 5, 2019
ea73393
add version string getter method
eli-darkly Mar 6, 2019
12fcfe1
Merge pull request #109 from launchdarkly/eb/ch33470/version-getter
eli-darkly Mar 6, 2019
723363d
Check for null key before file comparison check. (#110)
gwhelanLD Mar 8, 2019
2e6a5bf
[ch33658] Add unsafeReset() for LDClient testing re-initialization (#…
gwhelanLD Mar 12, 2019
7ca817e
[ch33846] Rename tests to not start with capitals and general refacto…
gwhelanLD Mar 12, 2019
071bfb5
Add documentation for flagstore implementation (#113)
gwhelanLD Mar 13, 2019
cf593d8
Merge branch 'master' into next-release
eli-darkly Mar 13, 2019
3777e9d
[ch35150] Unit tests and bug fixes (#114)
gwhelanLD Mar 28, 2019
77eff6f
Add compatibility behavior to stringVariation and allFlags methods. (…
gwhelanLD Mar 28, 2019
6606fa9
Merge branch 'master' of github.com:launchdarkly/android-client into …
gwhelanLD Apr 11, 2019
26ac3ee
Update LDUser not to store all fields as Json. (#116)
gwhelanLD Apr 11, 2019
4e76a48
Add metricValue field to CustomEvent, add overloaded track method for…
gwhelanLD Apr 19, 2019
c1e7510
Merge branch 'master' into next-release
gwhelanLD Apr 23, 2019
5cca201
[ch37794] Run connected emulator tests in CircleCI (#120)
gwhelanLD Apr 29, 2019
496fc69
[ch34533] connection status, removing guava, network restructuring. (…
gwhelanLD Apr 29, 2019
2215275
rename repo and package name and apply markdown templates (#121)
bwoskow-ld Apr 30, 2019
fdede38
Fix issue that stream could be started before stopping when calling i…
gwhelanLD May 2, 2019
697d870
Merge branch 'master' into next-release
gwhelanLD May 2, 2019
0849812
Revert "Fix issue that stream could be started before stopping when c…
bwoskow-ld May 3, 2019
bbbeb81
Revert "rename repo and package name and apply markdown templates (#1…
bwoskow-ld May 3, 2019
146ba99
Revert "Revert "Fix issue that stream could be started before stoppin…
bwoskow-ld May 3, 2019
330e2e2
Revert "Revert "rename repo and package name and apply markdown templ…
bwoskow-ld May 3, 2019
f202096
Merge branch 'master' of github.com:launchdarkly/android-client-sdk-p…
bwoskow-ld May 3, 2019
466318b
Merge branch 'master' into next-release
bwoskow-ld May 6, 2019
6f90344
Merge branch 'master' into next-release
bwoskow-ld May 6, 2019
e49b5f8
Fix thread leak on identify call from restarting EventProcessor witho…
gwhelanLD May 14, 2019
2e2e1a1
Merge branch 'master' into next-release
gwhelanLD May 21, 2019
d458246
Add top level try/catch to migration methods. Check flag version Shar…
gwhelanLD May 21, 2019
0f39494
Merge branch 'master' into next-release
gwhelanLD May 22, 2019
b6852af
Update Throttler to call runnable on background thread. (#125)
gwhelanLD Jun 14, 2019
c32e62b
Fix ConcurrentModificationException of instance map (#126)
gwhelanLD Jun 14, 2019
7ea8f8d
Merge branch 'master' into next-release
gwhelanLD Jun 14, 2019
2fb3e78
adding a circleci badge to the readme (#127)
bwoskow-ld Jul 5, 2019
bf50576
Fix bug where `stop` in StreamUpdateProcessor could not call it's lis…
gwhelanLD Jul 29, 2019
75ac7cf
Change LDAwaitFuture to not treat zero timeout as unlimited timeout
gwhelanLD Jul 29, 2019
d26e006
Merge branch 'master' into next-release
gwhelanLD Jul 29, 2019
3ac167f
Merge remote-tracking branch 'remotes/origin/experiment' into next-re…
gwhelanLD Sep 23, 2019
857451d
Revert "Merge remote-tracking branch 'remotes/origin/experiment' into…
gwhelanLD Oct 2, 2019
5088361
CircleCI fixes (#131)
gwhelanLD Oct 3, 2019
de0d059
Better ci fix (#132)
gwhelanLD Oct 7, 2019
56464a1
Speedup tests by building on macOS (#137)
gwhelanLD Oct 16, 2019
b653664
Background identify fixes (#133)
gwhelanLD Oct 16, 2019
6143d48
Experimentation 1.5 updates (#134)
gwhelanLD Oct 25, 2019
c9837e9
add entire compile-time classpath to javadoc classpath
eli-darkly Nov 14, 2019
17aee4a
javadoc fixes: <p/> is not a thing
eli-darkly Nov 14, 2019
05c2bc3
do fail on javadoc errors
eli-darkly Nov 14, 2019
bc68267
add javadoc step, misc CI cleanup
eli-darkly Nov 14, 2019
73e10da
misc javadoc fixes
eli-darkly Nov 14, 2019
8779723
Merge pull request #138 from launchdarkly/eb/ch56106/javadoc
eli-darkly Nov 14, 2019
f90b00d
remove unintentional(?) immediate event flush; clean up event tests
eli-darkly Nov 14, 2019
b1d45b9
remove unreliable test assumption about elapsed time
eli-darkly Nov 14, 2019
d1af310
Merge pull request #139 from launchdarkly/eb/ch56105/event-flush-tests
eli-darkly Nov 14, 2019
c0e71ae
[ch57098] Deprecate LDCountryCode (#141)
gwhelanLD Nov 25, 2019
ea19a16
Catch `SecurityException` when setting alarm in case there are alread…
gwhelanLD Dec 9, 2019
23b930f
Revert "[ch57098] Deprecate LDCountryCode (#141)" so we can do a patc…
gwhelanLD Jan 3, 2020
df8c273
Merge branch 'master' of github.com:launchdarkly/android-client-sdk
gwhelanLD Jan 3, 2020
7dd0e39
Revert "Revert "[ch57098] Deprecate LDCountryCode (#141)" so we can d…
gwhelanLD Jan 3, 2020
8519f7b
Deprecate public classes (#145)
gwhelanLD Jan 10, 2020
b598051
[ch61092] Add event payload ID. (#147)
gwhelanLD Jan 16, 2020
8ac37f0
Add event retry. (#149)
gwhelanLD Jan 24, 2020
c6dbf6f
Merge branch 'next-release'
gwhelanLD Jan 30, 2020
89f6e14
Fix javadoc comment for release.
gwhelanLD Jan 30, 2020
59169e1
Fix broken merge.
gwhelanLD Jan 30, 2020
f8d8da9
Merge branch 'master' of github.com:launchdarkly/android-client-sdk
gwhelanLD Jan 30, 2020
86989e9
[ch65133] Deprecate classes (#150)
gwhelanLD Feb 11, 2020
b99a268
Improve Javadoc and reduce interface clutter. (#152)
gwhelanLD Feb 12, 2020
4082207
Save Javadoc artifact and include logcat in circle output with tee. (…
gwhelanLD Feb 12, 2020
4f50176
[ch62120] Background during identify callback (#154)
gwhelanLD Feb 18, 2020
3de7975
[ch65914] Diagnostic events (#156)
gwhelanLD Feb 28, 2020
059dd08
Merge branch 'master' of github.com:launchdarkly/android-client-sdk
gwhelanLD Feb 28, 2020
1e29a82
[ch65352] Expose LDValue rather than Gson types (#158)
gwhelanLD Mar 13, 2020
b62a377
Remove SET_ALARM permission. The comment that this was required for b…
gwhelanLD Mar 20, 2020
e97a2d1
Fix minimum diagnostic recording interval comment. (#160)
gwhelanLD Mar 20, 2020
dfb8fed
Data since date was not getting reset after each periodic diagnostic …
gwhelanLD Mar 20, 2020
c06c619
[ch75315] Add maxCachedUsers configuration option (#162)
gwhelanLD May 27, 2020
1a49d7e
Configure okhttp cache for polling requests to be stored in a subdire…
gwhelanLD May 28, 2020
b2583c5
Fixes ch76614 and add test of null fallback unknown flag event genera…
gwhelanLD May 28, 2020
60ba2c3
Removing ldvalue changes before release (#165)
gwhelanLD May 29, 2020
644afee
Merge branch 'master' of github.com:launchdarkly/android-client-sdk
gwhelanLD May 29, 2020
c1106f0
[ch69437] Support for setting additional headers to be included in re…
gwhelanLD Aug 5, 2020
af59e9a
Update changelog and version.
gwhelanLD Aug 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@


All notable changes to the LaunchDarkly Android SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).

## [2.13.0] - 2020-08-07
### Added
- Allow specifying additional headers to be included on HTTP requests to LaunchDarkly services using `LDConfig.Builder.setAdditionalHeaders`. This feature is to enable certain proxy configurations, and is not needed for normal use.

## [2.12.0] - 2020-05-29
### Added
- Added a new configuration option, `maxCachedUsers` to LDConfig. This option allows configuration of the limit to how many users have their flag values cached locally in the device's SharedPreferences.
Expand Down
2 changes: 1 addition & 1 deletion example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation project(path: ':launchdarkly-android-client-sdk')
// Comment the previous line and uncomment this one to depend on the published artifact:
//implementation 'com.launchdarkly:launchdarkly-android-client-sdk:2.12.0'
//implementation 'com.launchdarkly:launchdarkly-android-client-sdk:2.13.0'

implementation 'com.jakewharton.timber:timber:4.7.1'

Expand Down
2 changes: 1 addition & 1 deletion launchdarkly-android-client-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply plugin: 'io.codearte.nexus-staging'

allprojects {
group = 'com.launchdarkly'
version = '2.12.0'
version = '2.13.0'
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.launchdarkly.android;

import android.net.Uri;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.launchdarkly.android.test.TestActivity;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.util.HashMap;

import okhttp3.OkHttpClient;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;

import static junit.framework.Assert.assertEquals;

@RunWith(AndroidJUnit4.class)
public class DiagnosticEventProcessorTest {

@Rule
public final ActivityTestRule<TestActivity> activityTestRule =
new ActivityTestRule<>(TestActivity.class, false, true);

private MockWebServer mockEventsServer;

@Before
public void before() throws IOException {
NetworkTestController.setup(activityTestRule.getActivity());
mockEventsServer = new MockWebServer();
mockEventsServer.start();
}

@After
public void after() throws InterruptedException, IOException {
NetworkTestController.enableNetwork();
mockEventsServer.close();
}

@Test
public void defaultDiagnosticRequest() throws InterruptedException {
// Setup in background to prevent initial diagnostic event
ForegroundTestController.setup(false);
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
LDConfig ldConfig = new LDConfig.Builder()
.setMobileKey("test-mobile-key")
.setEventsUri(Uri.parse(mockEventsServer.url("/mobile").toString()))
.build();
DiagnosticStore diagnosticStore = new DiagnosticStore(activityTestRule.getActivity().getApplication(), "test-mobile-key");
DiagnosticEventProcessor diagnosticEventProcessor = new DiagnosticEventProcessor(ldConfig, "default", diagnosticStore, okHttpClient);

DiagnosticEvent testEvent = new DiagnosticEvent("test-kind", System.currentTimeMillis(), diagnosticStore.getDiagnosticId());

mockEventsServer.enqueue(new MockResponse());
diagnosticEventProcessor.sendDiagnosticEventSync(testEvent);
RecordedRequest r = mockEventsServer.takeRequest();
assertEquals("POST", r.getMethod());
assertEquals("/mobile/events/diagnostic", r.getPath());
assertEquals("api_key test-mobile-key", r.getHeader("Authorization"));
assertEquals("AndroidClient/" + BuildConfig.VERSION_NAME, r.getHeader("User-Agent"));
assertEquals("application/json; charset=utf-8", r.getHeader("Content-Type"));
assertEquals(GsonCache.getGson().toJson(testEvent), r.getBody().readUtf8());
}

@Test
public void defaultDiagnosticRequestIncludingWrapper() throws InterruptedException {
// Setup in background to prevent initial diagnostic event
ForegroundTestController.setup(false);
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
LDConfig ldConfig = new LDConfig.Builder()
.setMobileKey("test-mobile-key")
.setEventsUri(Uri.parse(mockEventsServer.url("/mobile").toString()))
.setWrapperName("ReactNative")
.setWrapperVersion("1.0.0")
.build();
DiagnosticStore diagnosticStore = new DiagnosticStore(activityTestRule.getActivity().getApplication(), "test-mobile-key");
DiagnosticEventProcessor diagnosticEventProcessor = new DiagnosticEventProcessor(ldConfig, "default", diagnosticStore, okHttpClient);

DiagnosticEvent testEvent = new DiagnosticEvent("test-kind", System.currentTimeMillis(), diagnosticStore.getDiagnosticId());

mockEventsServer.enqueue(new MockResponse());
diagnosticEventProcessor.sendDiagnosticEventSync(testEvent);
RecordedRequest r = mockEventsServer.takeRequest();
assertEquals("POST", r.getMethod());
assertEquals("/mobile/events/diagnostic", r.getPath());
assertEquals("ReactNative/1.0.0", r.getHeader("X-LaunchDarkly-Wrapper"));
assertEquals(GsonCache.getGson().toJson(testEvent), r.getBody().readUtf8());
}

@Test
public void defaultDiagnosticRequestIncludingAdditionalHeaders() throws InterruptedException {
// Setup in background to prevent initial diagnostic event
ForegroundTestController.setup(false);
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();

HashMap<String, String> additionalHeaders = new HashMap<>();
additionalHeaders.put("Proxy-Authorization", "token");
additionalHeaders.put("Authorization", "foo");
LDConfig ldConfig = new LDConfig.Builder()
.setMobileKey("test-mobile-key")
.setEventsUri(Uri.parse(mockEventsServer.url("/mobile").toString()))
.setAdditionalHeaders(additionalHeaders)
.build();
DiagnosticStore diagnosticStore = new DiagnosticStore(activityTestRule.getActivity().getApplication(), "test-mobile-key");
DiagnosticEventProcessor diagnosticEventProcessor = new DiagnosticEventProcessor(ldConfig, "default", diagnosticStore, okHttpClient);

DiagnosticEvent testEvent = new DiagnosticEvent("test-kind", System.currentTimeMillis(), diagnosticStore.getDiagnosticId());

mockEventsServer.enqueue(new MockResponse());
diagnosticEventProcessor.sendDiagnosticEventSync(testEvent);
RecordedRequest r = mockEventsServer.takeRequest();
assertEquals("POST", r.getMethod());
assertEquals("/mobile/events/diagnostic", r.getPath());
assertEquals("token", r.getHeader("Proxy-Authorization"));
assertEquals("foo", r.getHeader("Authorization"));
assertEquals(GsonCache.getGson().toJson(testEvent), r.getBody().readUtf8());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.junit.runner.RunWith;

import java.io.IOException;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -478,6 +479,27 @@ public void variationFlagTrackReasonGeneratesEventWithReason() throws IOExceptio
}
}

@Test
public void additionalHeadersIncludedInEventsRequest() throws IOException, InterruptedException {
try (MockWebServer mockEventsServer = new MockWebServer()) {
mockEventsServer.start();
// Enqueue a successful empty response
mockEventsServer.enqueue(new MockResponse());

HashMap<String, String> additionalHeaders = new HashMap<>();
additionalHeaders.put("Proxy-Authorization", "token");
additionalHeaders.put("Authorization", "foo");
LDConfig ldConfig = baseConfigBuilder(mockEventsServer).setAdditionalHeaders(additionalHeaders).build();
try (LDClient client = LDClient.init(application, ldConfig, ldUser, 0)) {
client.blockingFlush();
}

RecordedRequest r = mockEventsServer.takeRequest();
assertEquals("token", r.getHeader("Proxy-Authorization"));
assertEquals("foo", r.getHeader("Authorization"));
}
}

private Event[] getEventsFromLastRequest(MockWebServer server, int expectedCount) throws InterruptedException {
RecordedRequest r = server.takeRequest();
assertEquals("POST", r.getMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.HashMap;
import java.util.HashSet;

import okhttp3.Request;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -45,6 +48,7 @@ public void testBuilderDefaults() {

assertNull(config.getWrapperName());
assertNull(config.getWrapperVersion());
assertNull(config.getAdditionalHeaders());
}


Expand Down Expand Up @@ -234,4 +238,41 @@ public void testBuilderMaxCachedUsers() {
config = new LDConfig.Builder().setMaxCachedUsers(-1).build();
assertEquals(-1, config.getMaxCachedUsers());
}

@Test
public void canSetAdditionalHeaders() {
HashMap<String, String> additionalHeaders = new HashMap<>();
additionalHeaders.put("Proxy-Authorization", "token");
additionalHeaders.put("Authorization", "foo");
LDConfig config = new LDConfig.Builder().setAdditionalHeaders(additionalHeaders).build();
assertEquals(2, config.getAdditionalHeaders().size());
assertEquals("token", config.getAdditionalHeaders().get("Proxy-Authorization"));
assertEquals("foo", config.getAdditionalHeaders().get("Authorization"));
}

@Test
public void buildRequestWithAdditionalHeadersNull() {
LDConfig config = new LDConfig.Builder().build();
Request.Builder requestBuilder = new Request.Builder()
.url("http://example.com")
.header("Authorization", "test-key");
Request request = config.buildRequestWithAdditionalHeaders(requestBuilder);
assertEquals(1, request.headers().size());
assertEquals("test-key", request.header("Authorization"));
}

@Test
public void buildRequestWithAdditionalHeaders() {
HashMap<String, String> additionalHeaders = new HashMap<>();
additionalHeaders.put("Proxy-Authorization", "token");
additionalHeaders.put("Authorization", "foo");
LDConfig config = new LDConfig.Builder().setAdditionalHeaders(additionalHeaders).build();
Request.Builder requestBuilder = new Request.Builder()
.url("http://example.com")
.header("Authorization", "test-key");
Request request = config.buildRequestWithAdditionalHeaders(requestBuilder);
assertEquals(2, request.headers().size());
assertEquals("token", request.header("Proxy-Authorization"));
assertEquals("foo", request.header("Authorization"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@ private void postEvents(List<Event> events) {
} catch (InterruptedException e) {}
}

Request request = config.getRequestBuilderFor(environmentName)
Request.Builder requestBuilder = config.getRequestBuilderFor(environmentName)
.url(url)
.post(RequestBody.create(JSON, content))
.addHeader("Content-Type", "application/json")
.addHeader("X-LaunchDarkly-Event-Schema", "3")
.addHeader("X-LaunchDarkly-Payload-ID", eventPayloadId)
.build();
.addHeader("X-LaunchDarkly-Payload-ID", eventPayloadId);

Request request = config.buildRequestWithAdditionalHeaders(requestBuilder);

Response response = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ public void run() {
});
}

private void sendDiagnosticEventSync(DiagnosticEvent diagnosticEvent) {
void sendDiagnosticEventSync(DiagnosticEvent diagnosticEvent) {
String content = GsonCache.getGson().toJson(diagnosticEvent);
Request.Builder requestBuilder = config.getRequestBuilderFor(environment)
.url(config.getEventsUri().toString() + "/events/diagnostic")
.addHeader("Content-Type", "application/json");
Request request = requestBuilder.post(RequestBody.create(JSON, content)).build();
.addHeader("Content-Type", "application/json")
.post(RequestBody.create(JSON, content));

Request request = config.buildRequestWithAdditionalHeaders(requestBuilder);
Timber.d("Posting diagnostic event to %s with body %s", request.url(), content);

Response response = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ private Request getDefaultRequest(LDUser user) {
uri += "?withReasons=true";
}
Timber.d("Attempting to fetch Feature flags using uri: %s", uri);
return config.getRequestBuilderFor(environmentName) // default GET verb
.url(uri)
.build();
Request.Builder requestBuilder = config.getRequestBuilderFor(environmentName) // default GET verb
.url(uri);
return config.buildRequestWithAdditionalHeaders(requestBuilder);
}

private Request getReportRequest(LDUser user) {
Expand All @@ -136,9 +136,9 @@ private Request getReportRequest(LDUser user) {
Timber.d("Attempting to report user using uri: %s", reportUri);
String userJson = GSON.toJson(user);
RequestBody reportBody = RequestBody.create(MediaType.parse("application/json;charset=UTF-8"), userJson);
return config.getRequestBuilderFor(environmentName)
Request.Builder requestBuilder = config.getRequestBuilderFor(environmentName)
.method("REPORT", reportBody) // custom REPORT verb
.url(reportUri)
.build();
.url(reportUri);
return config.buildRequestWithAdditionalHeaders(requestBuilder);
}
}
Loading