Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .idea/modules/sdk-java/countly-sdk-java.sdk-java.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules/sdk-java/countly-sdk-java.sdk-java.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules/sdk-java/countly-sdk-java.sdk-java.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 24.1.2

* Added e new configuration function "addCustomNetworkRequestHeaders(Map<String, String>)" to add custom request headers to each request.

## 24.1.1

* Added a new function "setID(newDeviceId)" for managing device id changes according to the device ID Type.
Expand Down
5 changes: 5 additions & 0 deletions app-java/src/main/java/ly/count/java/demo/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,14 @@ public static void main(String[] args) throws Exception {
}
}

Map<String, String> customNetworkRequestHeaders = new ConcurrentHashMap<>();
customNetworkRequestHeaders.put("X-Countly-Example", "true");
customNetworkRequestHeaders.put("X-Countly-Example-Version", "1.0");

Config config = new Config(COUNTLY_SERVER_URL, COUNTLY_APP_KEY, sdkStorageRootDirectory)
.setLoggingLevel(Config.LoggingLevel.DEBUG)
.setDeviceIdStrategy(Config.DeviceIdStrategy.UUID)
.addCustomNetworkRequestHeaders(customNetworkRequestHeaders)
.enableFeatures(Config.Feature.Events, Config.Feature.Sessions, Config.Feature.CrashReporting, Config.Feature.Views, Config.Feature.UserProfiles, Config.Feature.Location, Config.Feature.Feedback)
.setRequiresConsent(true)
//.enableParameterTamperingProtection("test-salt-checksum")
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ buildscript {
}

allprojects {
ext.CLY_VERSION = "24.1.1"
ext.CLY_VERSION = "24.1.2"
ext.POWERMOCK_VERSION = "1.7.4"

tasks.withType(Javadoc) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# org.gradle.parallel=true

# RELEASE FIELD SECTION
VERSION_NAME=24.1.1
VERSION_NAME=24.1.2
GROUP=ly.count.sdk

POM_URL=https://github.com/Countly/countly-sdk-java
Expand Down
22 changes: 21 additions & 1 deletion sdk-java/src/main/java/ly/count/sdk/java/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class Config {
/**
* Countly SDK version to be sent in HTTP requests
*/
protected String sdkVersion = "24.1.1";
protected String sdkVersion = "24.1.2";

/**
* Countly SDK version to be sent in HTTP requests
Expand Down Expand Up @@ -230,6 +230,12 @@ public class Config {
*/
protected boolean unhandledCrashReportingEnabled = true;

/**
* Custom network request headers to be sent with each request.
* If you want to add a header, use {@link #addCustomNetworkRequestHeaders(Map)}.
*/
protected Map<String, String> customNetworkRequestHeaders = null;

public ConfigViews views = new ConfigViews(this);

protected String location = null;
Expand Down Expand Up @@ -1330,6 +1336,20 @@ public Config disableLocation() {
return this;
}

/**
* Allows you to add custom header key/value pairs to each request
*
* @return Returns the same config object for convenient linking
*/
public Config addCustomNetworkRequestHeaders(Map<String, String> customHeaderValues) {
this.customNetworkRequestHeaders = customHeaderValues;
return this;
}

public Map<String, String> getCustomNetworkRequestHeaders() {
return customNetworkRequestHeaders;
}

/**
* Logging level for {@link Log} module
*/
Expand Down
12 changes: 12 additions & 0 deletions sdk-java/src/main/java/ly/count/sdk/java/internal/Transport.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ HttpURLConnection connection(final Request request) throws IOException {
https.setSSLSocketFactory(sslContext.getSocketFactory());
}

if (config.getCustomNetworkRequestHeaders() != null) {
//if there are custom header values, add them
L.v("[Transport] connection, Adding [" + config.getCustomNetworkRequestHeaders() + "] custom header fields");
for (Map.Entry<String, String> entry : config.getCustomNetworkRequestHeaders().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (key != null && value != null && !key.isEmpty()) {
connection.addRequestProperty(key, value);
}
}
}

if (!usingGET) {
OutputStream output = null;
PrintWriter writer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class TestUtils {
static String SERVER_APP_KEY = "COUNTLY_APP_KEY";
static String DEVICE_ID = "some_random_test_device_id";
static String SDK_NAME = "java-native";
static String SDK_VERSION = "24.1.1";
static String SDK_VERSION = "24.1.2";
static String APPLICATION_VERSION = "1.0";

public static final String[] eKeys = new String[] { "eventKey1", "eventKey2", "eventKey3", "eventKey4", "eventKey5", "eventKey6", "eventKey7" };
Expand Down
Loading