algoliasearch.internal.interceptor.AuthInterceptor.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algoliasearch-scala_3 Show documentation
Show all versions of algoliasearch-scala_3 Show documentation
Scala client for Algolia Search API
package algoliasearch.internal.interceptor
import okhttp3.{Interceptor, Response}
/** Interceptor that adds the application ID and API key to the request headers.
*
* @param applicationId
* application ID
* @param apiKey
* API key
*/
private[algoliasearch] class AuthInterceptor(
applicationId: String,
apiKey: String
) extends Interceptor {
private val HeaderApplicationId = "x-algolia-application-id"
private val HeaderApiKey = "x-algolia-api-key"
override def intercept(chain: Interceptor.Chain): Response = {
val originalRequest = chain.request()
val builder = originalRequest.newBuilder()
val headers = originalRequest.headers()
if (headers.get(HeaderApplicationId) == null) {
builder.header(HeaderApplicationId, applicationId)
}
if (headers.get(HeaderApiKey) == null) {
builder.header(HeaderApiKey, apiKey)
}
val newRequest = builder.build()
chain.proceed(newRequest)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy