Merge pull request #207 from connyduck/user-agent-2
Add a custom User-Agent
This commit is contained in:
commit
5e155badf5
1 changed files with 25 additions and 1 deletions
|
@ -37,7 +37,10 @@ import javax.net.ssl.TrustManagerFactory;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
import okhttp3.ConnectionSpec;
|
import okhttp3.ConnectionSpec;
|
||||||
|
import okhttp3.Interceptor;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
class OkHttpUtils {
|
class OkHttpUtils {
|
||||||
static final String TAG = "OkHttpUtils"; // logging tag
|
static final String TAG = "OkHttpUtils"; // logging tag
|
||||||
|
@ -69,6 +72,7 @@ class OkHttpUtils {
|
||||||
specList.add(ConnectionSpec.CLEARTEXT);
|
specList.add(ConnectionSpec.CLEARTEXT);
|
||||||
|
|
||||||
OkHttpClient.Builder builder = new OkHttpClient.Builder()
|
OkHttpClient.Builder builder = new OkHttpClient.Builder()
|
||||||
|
.addInterceptor(getUserAgentInterceptor())
|
||||||
.connectionSpecs(specList);
|
.connectionSpecs(specList);
|
||||||
|
|
||||||
return enableHigherTlsOnPreLollipop(builder);
|
return enableHigherTlsOnPreLollipop(builder);
|
||||||
|
@ -79,6 +83,26 @@ class OkHttpUtils {
|
||||||
return getCompatibleClientBuilder().build();
|
return getCompatibleClientBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a custom User-Agent that contains Tusky & Android Version to all requests
|
||||||
|
* Example:
|
||||||
|
* User-Agent: Tusky/1.1.2 Android/5.0.2
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
private static Interceptor getUserAgentInterceptor() {
|
||||||
|
return new Interceptor() {
|
||||||
|
@Override
|
||||||
|
public Response intercept(Chain chain) throws IOException {
|
||||||
|
Request originalRequest = chain.request();
|
||||||
|
Request requestWithUserAgent = originalRequest.newBuilder()
|
||||||
|
.header("User-Agent", "Tusky/"+BuildConfig.VERSION_NAME+" Android/"+Build.VERSION.RELEASE)
|
||||||
|
.build();
|
||||||
|
return chain.proceed(requestWithUserAgent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Android version Nougat has a regression where elliptic curve cipher suites are supported, but
|
* Android version Nougat has a regression where elliptic curve cipher suites are supported, but
|
||||||
* only the curve secp256r1 is allowed. So, first it's best to just disable all elliptic
|
* only the curve secp256r1 is allowed. So, first it's best to just disable all elliptic
|
||||||
|
|
Loading…
Reference in a new issue