Closed BrightVan closed 4 years ago
@Override
public void setCredentials(String username, String password, boolean isPreemptive) {
OkHttpClient.Builder builder = client.newBuilder();
List<Interceptor> interceptors = builder.interceptors();
for (Interceptor interceptor : interceptors) {
if (interceptor instanceof AuthenticationInterceptor) {
interceptors.remove(interceptor);
}
}
if (isPreemptive) {
builder.addInterceptor(new AuthenticationInterceptor(username, password));
} else {
builder.authenticator(new BasicAuthenticator(username, password));
}
this.client = builder.build();
}
public void clearCredentials() {
OkHttpClient.Builder builder = client.newBuilder();
builder.authenticator(Authenticator.NONE);
this.client = builder.build();
}
There's a constructor of OkHttpSardine
which takes a OkHttpClient
as parameter. Isn't this enough to manage the credentials yourself?
See https://github.com/thegrizzlylabs/sardine-android/blob/master/src/main/java/com/thegrizzlylabs/sardineandroid/impl/OkHttpSardine.java#L76
There's a constructor of
OkHttpSardine
which takes aOkHttpClient
as parameter. Isn't this enough to manage the credentials yourself? See https://github.com/thegrizzlylabs/sardine-android/blob/master/src/main/java/com/thegrizzlylabs/sardineandroid/impl/OkHttpSardine.java#L76 the question isclient.newBuilder().build()
will create a new Object,the constructor's parameterOkHttpClient
is just a init object, they are not same.anyway, i clone and custom the code as above. of cource, there is no question if create a newOkHttpSardine
object every time.
Sardine contains a okhttpClient, but it is private. when i use a sington to reuse the sardine instance, if "isPreemptive "set TRUE, it will cause error at switch webdav server. i want to remove the interceptor, but i can not access the okhttpClient.