Perhaps an application Interceptorfor your OkHttp client that decrypts the body will do the trick:
public class DecryptedPayloadInterceptor implements Interceptor {
private final DecryptionStrategy mDecryptionStrategy;
public interface DecryptionStrategy {
String decrypt(InputStream stream);
}
public DecryptedPayloadInterceptor(DecryptionStrategy mDecryptionStrategy) {
this.mDecryptionStrategy = mDecryptionStrategy;
}
@Override
public Response intercept(Chain chain) throws IOException {
Response response = chain.proceed(chain.request());
if (response.isSuccessful()) {
Response.Builder newResponse = response.newBuilder();
String contentType = response.header("Content-Type");
if (TextUtils.isEmpty(contentType)) contentType = "application/json";
InputStream cryptedStream = response.body().byteStream();
String decrypted = null;
if (mDecryptionStrategy != null) {
decrypted = mDecryptionStrategy.decrypt(cryptedStream);
} else {
throw new IllegalArgumentException("No decryption strategy!");
}
newResponse.body(ResponseBody.create(MediaType.parse(contentType), decrypted));
return newResponse.build();
}
return response;
}
}
If you are not using OkHttp, I will gracefully delete the answer.
source
share