Skip to content

Add Ktor HTTP data source module#3071

Open
k88936 wants to merge 32 commits intoandroidx:mainfrom
k88936:feat/ktor-datasource
Open

Add Ktor HTTP data source module#3071
k88936 wants to merge 32 commits intoandroidx:mainfrom
k88936:feat/ktor-datasource

Conversation

@k88936
Copy link
Copy Markdown

@k88936 k88936 commented Feb 14, 2026

Summary

Introduce a new lib-datasource-ktor module similar to libraries/datasource_okhttp, providing KtorDataSource as an alternative HTTP data source implementation using Ktor client to solve issue #1646 .

What changed

  • impl: androidx.media3.datasource.DataSource using ktor
  • test: a unit test for DataSourceContractTest. and a unit test for it own.
  • api.txt in the repo root
  • some gradle config for include this module

Why

I recent met the same problem for maintaining both a okhttp client and a ktor client, similar to #1646 (comment)

Comment thread libraries/datasource_ktor/proguard-rules.txt Outdated
Copy link
Copy Markdown
Collaborator

@icbaker icbaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a few commits, and added a few comments too

Comment thread libraries/datasource_ktor/build.gradle Outdated
Comment thread libraries/datasource_ktor/README.md
@k88936 k88936 force-pushed the feat/ktor-datasource branch 3 times, most recently from c0f7038 to 919b31d Compare February 25, 2026 04:10
@k88936 k88936 requested a review from icbaker February 25, 2026 04:31
@icbaker icbaker force-pushed the feat/ktor-datasource branch from c6ae2f3 to ca7ae8c Compare March 10, 2026 13:57
@icbaker icbaker force-pushed the feat/ktor-datasource branch from dcc4c38 to 3a43094 Compare March 19, 2026 12:22
@k88936 k88936 requested a review from icbaker March 23, 2026 12:41
@k88936 k88936 force-pushed the feat/ktor-datasource branch from 8231c9d to cacf0ad Compare March 31, 2026 09:36
@icbaker icbaker force-pushed the feat/ktor-datasource branch 4 times, most recently from 0f26e79 to a70c5c2 Compare April 8, 2026 08:56
@icbaker
Copy link
Copy Markdown
Collaborator

icbaker commented Apr 8, 2026

I'm going to send this for internal review now. You may see some more commits being added as I make changes in response to review feedback. Please refrain from pushing any more substantive changes as it will complicate the internal review - thanks!

k88936 and others added 8 commits April 15, 2026 15:41
Introduce a new lib-datasource-ktor module similar to `libraries/datasource_okhttp`.
 Providing KtorDataSource as an alternative HTTP data source implementation using Ktor client.
In the past we have found Robolectric is not realistic enough for
testing fiddly edge cases in HTTP stacks, so running on an emulator with
real Android OS is better.
We can promote it to stable later
k88936 and others added 22 commits April 15, 2026 15:41
io.ktor.http.Headers it self is a case-insensitive map already
This reverts commit b51daad.

fix: failed test case , we not only need a case-insensitively stored map,
 we also need a case-insensitively look up map.
Also explcitly use Android client in the tests (our internal test infra
fails to automatically identify a client, so this is needed to get the
tests passing internally)

And reformat some things with ktfmt
…gent`, `setContentTypePredicate`, and `setTransferListener`
…age.

should use readRemaining instead of readAvailable
* Run tests with both `android` and `okhttp` engines
* Use `HttpUtil.getContentLength` to consider both `Content-Length` and
  `Content-Range` headers.
* Add tests for cookie handling (including redirects)
@icbaker icbaker force-pushed the feat/ktor-datasource branch from 2cd3f8e to 8c77927 Compare April 15, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants