Search in sources :

Example 91 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project FastHub by k0shk0sh.

the class LoginProvider method provideOkHttpClient.

private static OkHttpClient provideOkHttpClient(@Nullable String authToken, @Nullable String otp) {
    OkHttpClient.Builder client = new OkHttpClient.Builder();
    if (BuildConfig.DEBUG) {
        client.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
    }
    client.addInterceptor(new AuthenticationInterceptor(authToken, otp));
    return client.build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) AuthenticationInterceptor(com.fastaccess.provider.rest.interceptors.AuthenticationInterceptor) GsonBuilder(com.google.gson.GsonBuilder) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 92 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project FastHub by k0shk0sh.

the class RestProvider method provideOkHttpClient.

public static OkHttpClient provideOkHttpClient() {
    if (okHttpClient == null) {
        OkHttpClient.Builder client = new OkHttpClient.Builder();
        if (BuildConfig.DEBUG) {
            client.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
        }
        client.addInterceptor(new AuthenticationInterceptor());
        client.addInterceptor(new PaginationInterceptor());
        client.addInterceptor(new ContentTypeInterceptor());
        okHttpClient = client.build();
    }
    return okHttpClient;
}
Also used : OkHttpClient(okhttp3.OkHttpClient) AuthenticationInterceptor(com.fastaccess.provider.rest.interceptors.AuthenticationInterceptor) GsonBuilder(com.google.gson.GsonBuilder) ContentTypeInterceptor(com.fastaccess.provider.rest.interceptors.ContentTypeInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) PaginationInterceptor(com.fastaccess.provider.rest.interceptors.PaginationInterceptor)

Example 93 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project okhttp-digest by rburgst.

the class BasicAuthenticatorWithMockWebserverTest method setUp.

@Before
public void setUp() throws Exception {
    credentials = new Credentials("user1", "user1");
    sut = new BasicAuthenticator(credentials);
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>();
    HttpLoggingInterceptor logger = new HttpLoggingInterceptor(new StdOutLogger());
    logger.setLevel(HttpLoggingInterceptor.Level.HEADERS);
    spy = spy(sut);
    client = builder.authenticator(new CachingAuthenticatorDecorator(spy, authCache)).addInterceptor(new AuthenticationCacheInterceptor(authCache)).addNetworkInterceptor(logger).build();
    unauthorizedResponse = new MockResponse().setResponseCode(401).addHeader("WWW-Authenticate", "Basic realm=\"myrealm\"");
    successResponse = new MockResponse().setBody("OK");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) OkHttpClient(okhttp3.OkHttpClient) CachingAuthenticator(com.burgstaller.okhttp.digest.CachingAuthenticator) CachingAuthenticatorDecorator(com.burgstaller.okhttp.CachingAuthenticatorDecorator) AuthenticationCacheInterceptor(com.burgstaller.okhttp.AuthenticationCacheInterceptor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Credentials(com.burgstaller.okhttp.digest.Credentials) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Before(org.junit.Before)

Example 94 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project RxReddit by damien5314.

the class RedditService method getOkHttpClient.

protected OkHttpClient getOkHttpClient(String userAgent, int cacheSizeBytes, File cachePath, boolean loggingEnabled) {
    OkHttpClient.Builder builder = new OkHttpClient.Builder().addNetworkInterceptor(new UserAgentInterceptor(userAgent)).addNetworkInterceptor(new RawResponseInterceptor()).addNetworkInterceptor(getUserAuthInterceptor());
    if (cacheSizeBytes > 0) {
        builder.cache(new Cache(cachePath, cacheSizeBytes));
    }
    if (loggingEnabled) {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
        builder.addInterceptor(loggingInterceptor);
    }
    return builder.build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Cache(okhttp3.Cache)

Example 95 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project TeamCityApp by vase4kin.

the class AppModule method providesBaseHttpClient.

@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
@Named(CLIENT_BASE)
@Singleton
@Provides
protected OkHttpClient providesBaseHttpClient() {
    OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder().connectTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS).readTimeout(READ_TIMEOUT, TimeUnit.SECONDS).writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS);
    // TODO: Use DI separated modules for debug and release which will be holding this interceptor
    if (BuildConfig.DEBUG) {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        clientBuilder.addInterceptor(loggingInterceptor);
    }
    return clientBuilder.build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) VisibleForTesting(android.support.annotation.VisibleForTesting) Named(javax.inject.Named) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Aggregations

HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)107 OkHttpClient (okhttp3.OkHttpClient)87 Provides (dagger.Provides)27 Retrofit (retrofit2.Retrofit)25 GsonBuilder (com.google.gson.GsonBuilder)24 Singleton (javax.inject.Singleton)24 Cache (okhttp3.Cache)19 Request (okhttp3.Request)16 File (java.io.File)15 Response (okhttp3.Response)15 IOException (java.io.IOException)14 Gson (com.google.gson.Gson)13 Interceptor (okhttp3.Interceptor)11 StethoInterceptor (com.facebook.stetho.okhttp3.StethoInterceptor)6 LoggingInterceptor (com.toshi.manager.network.interceptor.LoggingInterceptor)6 List (java.util.List)5 ErrorInterceptor (me.postaddict.instagram.scraper.interceptor.ErrorInterceptor)5 FakeBrowserInterceptor (me.postaddict.instagram.scraper.interceptor.FakeBrowserInterceptor)5 ResponseBody (okhttp3.ResponseBody)5 BeforeClass (org.junit.BeforeClass)5