-
Notifications
You must be signed in to change notification settings - Fork 58
Send the SDK name and version as X-Stream-Client on SFU requests #1818
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
954da16
feat(core): send X-Stream-Client on SFU Twirp requests
aleksandar-apostolov 2af56df
fix(core): use the stream-video-android prefix in the SFU client header
aleksandar-apostolov 4697a85
fix(core): match the coordinator version format in the SFU client header
aleksandar-apostolov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
.../src/main/kotlin/io/getstream/video/android/core/internal/module/SfuHeadersInterceptor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright (c) 2014-2026 Stream.io Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Stream License; | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/GetStream/stream-video-android/blob/main/LICENSE | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.getstream.video.android.core.internal.module | ||
|
|
||
| import io.getstream.video.android.core.header.HeadersUtil | ||
| import okhttp3.Interceptor | ||
| import okhttp3.Response | ||
|
|
||
| internal class SfuHeadersInterceptor(private val headersUtil: HeadersUtil) : Interceptor { | ||
| override fun intercept(chain: Interceptor.Chain): Response { | ||
| val request = chain.request() | ||
| .newBuilder() | ||
| .addHeader("X-Stream-Client", headersUtil.buildSfuSdkTrackingHeader()) | ||
| .build() | ||
| return chain.proceed(request) | ||
| } | ||
| } |
70 changes: 70 additions & 0 deletions
70
.../test/kotlin/io/getstream/video/android/core/internal/module/SfuHeadersInterceptorTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright (c) 2014-2026 Stream.io Inc. All rights reserved. | ||
| * | ||
| * Licensed under the Stream License; | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://github.com/GetStream/stream-video-android/blob/main/LICENSE | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.getstream.video.android.core.internal.module | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import io.getstream.video.android.core.BuildConfig | ||
| import io.getstream.video.android.core.header.HeadersUtil | ||
| import okhttp3.Interceptor | ||
| import okhttp3.OkHttpClient | ||
| import okhttp3.Protocol | ||
| import okhttp3.Request | ||
| import okhttp3.Response | ||
| import okhttp3.ResponseBody.Companion.toResponseBody | ||
| import org.junit.Test | ||
|
|
||
| class SfuHeadersInterceptorTest { | ||
|
aleksandar-apostolov marked this conversation as resolved.
|
||
|
|
||
| private val twirpUrl = "https://sfu.example.com/twirp/signal.SignalServer/SendStats" | ||
|
|
||
| @Test | ||
| fun `identifies the SDK and its version on every twirp request`() { | ||
| val request = sendTwirpRequest() | ||
|
|
||
| assertThat(request.header("X-Stream-Client")) | ||
| .isEqualTo("stream-video-android-v${BuildConfig.STREAM_VIDEO_VERSION}") | ||
| } | ||
|
|
||
| @Test | ||
| fun `sends a single client header`() { | ||
| val request = sendTwirpRequest() | ||
|
|
||
| assertThat(request.headers("X-Stream-Client")).hasSize(1) | ||
| } | ||
|
|
||
| private fun sendTwirpRequest(): Request { | ||
| lateinit var sent: Request | ||
| val client = OkHttpClient.Builder() | ||
| .addInterceptor(SfuHeadersInterceptor(HeadersUtil())) | ||
| .addInterceptor( | ||
| Interceptor { chain -> | ||
| sent = chain.request() | ||
| Response.Builder() | ||
| .request(chain.request()) | ||
| .protocol(Protocol.HTTP_1_1) | ||
| .code(200) | ||
| .message("OK") | ||
| .body("".toResponseBody()) | ||
| .build() | ||
| }, | ||
| ) | ||
| .build() | ||
|
|
||
| client.newCall(Request.Builder().url(twirpUrl).build()).execute().close() | ||
| return sent | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.