Skip to content

Commit 13d847e

Browse files
Vivek Maskaramisaochan
Vivek Maskara
authored andcommitted
Basic logging with redacted sensitive headers (#3159)
1 parent 2e0281e commit 13d847e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ dependencies {
5353
api('com.github.tony19:logback-android-classic:1.1.1-6') {
5454
exclude group: 'com.google.android', module: 'android'
5555
}
56+
implementation "com.squareup.okhttp3:logging-interceptor:4.2.0"
5657

5758
// Dependency injector
5859
implementation "com.google.dagger:dagger:$DAGGER_VERSION"

app/src/main/java/fr/free/nrw/commons/OkHttpConnectionFactory.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,22 @@ private static OkHttpClient createClient() {
3131
return new OkHttpClient.Builder()
3232
.cookieJar(SharedPreferenceCookieManager.getInstance())
3333
.cache(NET_CACHE)
34-
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
34+
.addInterceptor(getLoggingInterceptor())
3535
.addInterceptor(new UnsuccessfulResponseInterceptor())
3636
.addInterceptor(new CommonHeaderRequestInterceptor())
3737
.build();
3838
}
3939

40+
private static HttpLoggingInterceptor getLoggingInterceptor() {
41+
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor()
42+
.setLevel(HttpLoggingInterceptor.Level.BASIC);
43+
44+
httpLoggingInterceptor.redactHeader("Authorization");
45+
httpLoggingInterceptor.redactHeader("Cookie");
46+
47+
return httpLoggingInterceptor;
48+
}
49+
4050
private static class CommonHeaderRequestInterceptor implements Interceptor {
4151
@Override @NonNull public Response intercept(@NonNull Chain chain) throws IOException {
4252
Request request = chain.request().newBuilder()

0 commit comments

Comments
 (0)