-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add param
forceSAM=true
when targeting sam endpoint (#56)
# Description All sam call need to have the param `forceSAM=true` to ensure call are retrieved from SAM and not proxied through IL. # Changes made: - Add `HostInterceptor` to add param `forceSAM=true` to all calls made to sam end points (prod, stage, test).
- Loading branch information
1 parent
43466f8
commit 280f2d2
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
33 changes: 33 additions & 0 deletions
33
...ider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/utils/HostInterceptor.kt
This file contains 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,33 @@ | ||
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(FORCE_SAM) != null || !originalHttpUrl.pathSegments.contains("sam")) { | ||
return chain.proceed(originalRequest) | ||
} | ||
|
||
val url = originalHttpUrl.newBuilder() | ||
.addQueryParameter(FORCE_SAM, "true") | ||
.build() | ||
|
||
// Request customization: add request headers | ||
val requestBuilder = originalRequest.newBuilder().url(url) | ||
val request = requestBuilder.build() | ||
return chain.proceed(request) | ||
} | ||
|
||
companion object { | ||
private const val FORCE_SAM = "forceSAM" | ||
} | ||
} |