use of okhttp3.internal.cache.InternalCache in project okhttp by square.
the class URLEncodingTest method backdoorUrlToUri.
private URI backdoorUrlToUri(URL url) throws Exception {
final AtomicReference<URI> uriReference = new AtomicReference<>();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
Internal.instance.setCache(builder, new InternalCache() {
@Override
public Response get(Request request) throws IOException {
uriReference.set(request.url().uri());
throw new UnsupportedOperationException();
}
@Override
public CacheRequest put(Response response) throws IOException {
return null;
}
@Override
public void remove(Request request) throws IOException {
}
@Override
public void update(Response cached, Response network) {
}
@Override
public void trackConditionalCacheHit() {
}
@Override
public void trackResponse(CacheStrategy cacheStrategy) {
}
});
try {
HttpURLConnection connection = new OkUrlFactory(builder.build()).open(url);
connection.getResponseCode();
} catch (Exception expected) {
if (expected.getCause() instanceof URISyntaxException) {
expected.printStackTrace();
}
}
return uriReference.get();
}
Aggregations