mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 15:11:58 +01:00
net: send the subtracks user agent on every request
Only SubsonicClient tagged requests with 'subtracks/android'; playback (Media3 OkHttpDataSource), downloads (DownloadManager) and artwork (Coil/OkHttpArtworkFetcher) fell back to the OkHttp or platform default. Add a single UserAgent with the app version, apply it to the shared OkHttp client, the streaming data source factory and the DownloadManager request, and drop SubsonicClient's now-redundant header.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.subtracks
|
||||
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.mockwebserver.MockResponse
|
||||
import okhttp3.mockwebserver.MockWebServer
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class UserAgentTest {
|
||||
@Test
|
||||
fun addsTheSubtracksUserAgent() {
|
||||
val server = MockWebServer()
|
||||
server.enqueue(MockResponse())
|
||||
server.start()
|
||||
val client = OkHttpClient.Builder().addInterceptor(UserAgent.interceptor()).build()
|
||||
|
||||
client.newCall(Request.Builder().url(server.url("/")).build()).execute().close()
|
||||
val header = server.takeRequest().getHeader("User-Agent")
|
||||
server.shutdown()
|
||||
|
||||
assertEquals(UserAgent.value, header)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user