Skip to content
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

Add param forceSAM=true when targeting sam endpoint #56

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ object Config {
const val minSdk = 21

const val major = 0
const val minor = 10
const val patch = 1
const val minor = 11
const val patch = "0.test-force-sam"
const val versionName = "$major.$minor.$patch"

const val maven_group = "ch.srg.data.provider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ch.srg.dataProvider.integrationlayer.dependencies.modules

import android.content.Context
import android.content.res.Configuration
import ch.srg.dataProvider.integrationlayer.utils.HostInterceptor
import ch.srg.dataProvider.integrationlayer.utils.UserAgentInterceptor
import ch.srg.dataProvider.integrationlayer.utils.UserAgentUtils
import ch.srg.dataProvider.integrationlayer.utils.VectorInterceptor
Expand Down Expand Up @@ -31,6 +32,7 @@ object OkHttpModule {
logging.setLevel(HttpLoggingInterceptor.Level.HEADERS)
builder.addInterceptor(logging)
builder.addInterceptor(UserAgentInterceptor(UserAgentUtils.createUserAgent(context)))
builder.addInterceptor(HostInterceptor())
builder.addInterceptor(VectorInterceptor(vector))
builder.readTimeout(READ_TIMEOUT_SECONDS, TimeUnit.SECONDS)
builder.connectTimeout(CONNECT_TIMEOUT_SECONDS, TimeUnit.SECONDS)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ch.srg.dataProvider.integrationlayer.utils

import okhttp3.Interceptor
import okhttp3.Response

/**
* Adds a query parameter "forceSAM=true" to each SAM HTTP request.
* See [IlHost] for more details.
*/
class HostInterceptor : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {
val originalRequest = chain.request()
val originalHttpUrl = originalRequest.url

if (originalHttpUrl.queryParameter("forceSAM") != null || !originalHttpUrl.pathSegments.contains("sam")) {
return chain.proceed(originalRequest)
}

val url = originalHttpUrl.newBuilder()
.addQueryParameter("forceSAM", "true")
.build()

// Request customization: add request headers
val requestBuilder = originalRequest.newBuilder().url(url)
val request = requestBuilder.build()
return chain.proceed(request)
}
}
Loading