Basic logging with redacted sensitive headers (#3159)

This commit is contained in:
Vivek Maskara 2019-10-05 17:06:35 +05:30 committed by Josephine Lim
parent 2e0281eaee
commit 13d847ea77
2 changed files with 12 additions and 1 deletions

View file

@ -31,12 +31,22 @@ public final class OkHttpConnectionFactory {
return new OkHttpClient.Builder()
.cookieJar(SharedPreferenceCookieManager.getInstance())
.cache(NET_CACHE)
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.addInterceptor(getLoggingInterceptor())
.addInterceptor(new UnsuccessfulResponseInterceptor())
.addInterceptor(new CommonHeaderRequestInterceptor())
.build();
}
private static HttpLoggingInterceptor getLoggingInterceptor() {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor()
.setLevel(HttpLoggingInterceptor.Level.BASIC);
httpLoggingInterceptor.redactHeader("Authorization");
httpLoggingInterceptor.redactHeader("Cookie");
return httpLoggingInterceptor;
}
private static class CommonHeaderRequestInterceptor implements Interceptor {
@Override @NonNull public Response intercept(@NonNull Chain chain) throws IOException {
Request request = chain.request().newBuilder()