Skip to content

Commit ec4843a

Browse files
rafaelmf3Rafael Marinho
andauthored
[CHA-1558] support ext custom header (#230)
* [CHA-1558] support ext custom header * fix format --------- Co-authored-by: Rafael Marinho <rafael.marinho@getstream.io>
1 parent 9f22588 commit ec4843a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/java/io/getstream/chat/java/services/framework/DefaultClient.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class DefaultClient implements Client {
3232
public static final String API_SECRET_PROP_NAME = "io.getstream.chat.apiSecret";
3333
public static final String API_TIMEOUT_PROP_NAME = "io.getstream.chat.timeout";
3434
public static final String API_URL_PROP_NAME = "io.getstream.chat.url";
35+
public static final String X_STREAM_EXT_PROP_NAME = "io.getstream.chat.xStreamExt";
3536

3637
private static final String API_DEFAULT_URL = "https://chat.stream-io-api.com";
3738
private static volatile DefaultClient defaultInstance;
@@ -121,6 +122,12 @@ private OkHttpClient buildOkHttpClient() {
121122
.header("X-Stream-Client", "stream-java-client-" + sdkVersion)
122123
.header("Stream-Auth-Type", "jwt");
123124

125+
// Add x-stream-ext header if configured
126+
String xStreamExt = getXStreamExt(extendedProperties);
127+
if (xStreamExt != null && !xStreamExt.isEmpty()) {
128+
builder.header("X-Stream-Ext", xStreamExt);
129+
}
130+
124131
if (userToken != null) {
125132
// User token present - use user auth
126133
builder.header("Authorization", userToken.value());
@@ -231,6 +238,13 @@ private static Properties extendProperties(Properties properties) {
231238
canformedProperties.put(API_URL_PROP_NAME, envApiUrl);
232239
}
233240

241+
var envXStreamExt =
242+
env.getOrDefault(
243+
"STREAM_CHAT_X_STREAM_EXT", System.getProperty("STREAM_CHAT_X_STREAM_EXT"));
244+
if (envXStreamExt != null) {
245+
canformedProperties.put(X_STREAM_EXT_PROP_NAME, envXStreamExt);
246+
}
247+
234248
canformedProperties.putAll(System.getProperties());
235249
canformedProperties.putAll(properties);
236250
return canformedProperties;
@@ -246,6 +260,11 @@ private static String getStreamChatBaseUrl(@NotNull Properties properties) {
246260
return url.toString();
247261
}
248262

263+
private static String getXStreamExt(@NotNull Properties properties) {
264+
var xStreamExt = properties.get(X_STREAM_EXT_PROP_NAME);
265+
return xStreamExt != null ? xStreamExt.toString() : null;
266+
}
267+
249268
private static final @NotNull String sdkVersion = getSdkVersion();
250269

251270
private static @NotNull String getSdkVersion() {

0 commit comments

Comments
 (0)