Skip to content

Commit

Permalink
Add User-Agent header (#39)
Browse files Browse the repository at this point in the history
Change-Id: I9306b1dc140620d9dfb59357e1acc4017d4112b3
  • Loading branch information
jdkoren authored Sep 28, 2021
1 parent 46ba00b commit 6ab04bd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.android.fido2

import android.app.Application
import android.os.Build
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
Expand All @@ -43,8 +44,10 @@ object AppModule {
@Singleton
@Provides
fun provideOkHttpClient() : OkHttpClient {
val userAgent = "${BuildConfig.APPLICATION_ID}/${BuildConfig.VERSION_NAME} " +
"(Android ${Build.VERSION.RELEASE}; ${Build.MODEL}; ${Build.BRAND})"
return OkHttpClient.Builder()
.addInterceptor(AddHeaderInterceptor())
.addInterceptor(AddHeaderInterceptor(userAgent))
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(40, TimeUnit.SECONDS)
.connectTimeout(40, TimeUnit.SECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ package com.example.android.fido2.api
import okhttp3.Interceptor
import okhttp3.Response

internal class AddHeaderInterceptor : Interceptor {
internal class AddHeaderInterceptor(private val userAgent: String) : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {
return chain.proceed(
chain.request().newBuilder()
.header("User-Agent", userAgent)
.header("X-Requested-With", "XMLHttpRequest")
.build()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.android.fido2

import android.app.Application
import android.os.Build
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
Expand All @@ -43,8 +44,10 @@ object AppModule {
@Singleton
@Provides
fun provideOkHttpClient() : OkHttpClient {
val userAgent = "${BuildConfig.APPLICATION_ID}/${BuildConfig.VERSION_NAME} " +
"(Android ${Build.VERSION.RELEASE}; ${Build.MODEL}; ${Build.BRAND})"
return OkHttpClient.Builder()
.addInterceptor(AddHeaderInterceptor())
.addInterceptor(AddHeaderInterceptor(userAgent))
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(40, TimeUnit.SECONDS)
.connectTimeout(40, TimeUnit.SECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ package com.example.android.fido2.api
import okhttp3.Interceptor
import okhttp3.Response

internal class AddHeaderInterceptor : Interceptor {
internal class AddHeaderInterceptor(private val userAgent: String) : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {
return chain.proceed(
chain.request().newBuilder()
.header("User-Agent", userAgent)
.header("X-Requested-With", "XMLHttpRequest")
.build()
)
Expand Down

0 comments on commit 6ab04bd

Please sign in to comment.