add Accept: application/json to all api requests

This commit is contained in:
Konrad Pozniak 2020-06-17 15:00:11 +02:00
parent 99c1a3ec87
commit 803bcbb4b7
1 changed files with 5 additions and 2 deletions

View File

@ -5,7 +5,6 @@ import kotlinx.coroutines.runBlocking
import okhttp3.HttpUrl
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException
class InstanceSwitchAuthInterceptor(private val accountManager: AccountManager) : Interceptor {
@ -18,9 +17,13 @@ class InstanceSwitchAuthInterceptor(private val accountManager: AccountManager)
// only switch domains if the request comes from retrofit
if (originalRequest.url.host == FediverseApi.PLACEHOLDER_DOMAIN) {
val currentAccount = runBlocking { accountManager.activeAccount() }
val builder = originalRequest.newBuilder()
// when using retrofit we want json responses
builder.addHeader("Accept", "application/json")
val currentAccount = runBlocking { accountManager.activeAccount() }
val instanceHeader = originalRequest.header(FediverseApi.DOMAIN_HEADER)
if (instanceHeader != null) {
// use domain explicitly specified in custom header