use of java.net.CacheRequest in project android_frameworks_base by ParanoidAndroid.
the class HttpResponseCacheTest method testGetInstalledWithWrongTypeInstalled.
public void testGetInstalledWithWrongTypeInstalled() {
ResponseCache.setDefault(new ResponseCache() {
@Override
public CacheResponse get(URI uri, String requestMethod, Map<String, List<String>> requestHeaders) {
return null;
}
@Override
public CacheRequest put(URI uri, URLConnection connection) {
return null;
}
});
assertNull(HttpResponseCache.getInstalled());
}
use of java.net.CacheRequest in project robovm by robovm.
the class URLConnectionTest method backdoorUrlToUri.
/**
* Exercises HttpURLConnection to convert URL to a URI. Unlike URL#toURI,
* HttpURLConnection recovers from URLs with unescaped but unsupported URI
* characters like '{' and '|' by escaping these characters.
*/
private URI backdoorUrlToUri(URL url) throws Exception {
final AtomicReference<URI> uriReference = new AtomicReference<URI>();
ResponseCache.setDefault(new ResponseCache() {
@Override
public CacheRequest put(URI uri, URLConnection connection) throws IOException {
return null;
}
@Override
public CacheResponse get(URI uri, String requestMethod, Map<String, List<String>> requestHeaders) throws IOException {
uriReference.set(uri);
throw new UnsupportedOperationException();
}
});
try {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.getResponseCode();
} catch (Exception expected) {
}
return uriReference.get();
}
use of java.net.CacheRequest in project okhttp by square.
the class ResponseCacheTest method responseCacheReturnsNullOutputStream.
/** Don't explode if the cache returns a null body. http://b/3373699 */
@Test
public void responseCacheReturnsNullOutputStream() throws Exception {
final AtomicBoolean aborted = new AtomicBoolean();
setInternalCache(new CacheAdapter(new AbstractResponseCache() {
@Override
public CacheRequest put(URI uri, URLConnection connection) {
return new CacheRequest() {
@Override
public void abort() {
aborted.set(true);
}
@Override
public OutputStream getBody() throws IOException {
return null;
}
};
}
}));
server.enqueue(new MockResponse().setBody("abcdef"));
HttpURLConnection connection = openConnection(server.url("/").url());
assertEquals("abc", readAscii(connection, 3));
connection.getInputStream().close();
// The best behavior is ambiguous, but RI 6 doesn't abort here
assertFalse(aborted.get());
}
use of java.net.CacheRequest in project enroscar by stanfy.
the class TestUtils method putCachedContent.
static void putCachedContent(final ImagesManager manager, final String url) throws Exception {
CacheRequest cacheRequest = manager.getImagesResponseCache().put(new URI(url), fakeConnection(new URL(url)));
OutputStream out = cacheRequest.getBody();
out.write(new byte[] { 1 });
out.close();
}
use of java.net.CacheRequest in project j2objc by google.
the class URLConnectionTest method testResponseCacheReturnsNullOutputStream.
// TODO(tball): b/28067294
// public void testHostWithNul() throws Exception {
// URL url = new URL("http://host /");
// try {
// url.openStream();
// fail();
// } catch (UnknownHostException expected) {
// } catch (IllegalArgumentException expected) {
// }
// }
/**
* Don't explode if the cache returns a null body. http://b/3373699
*/
public void testResponseCacheReturnsNullOutputStream() throws Exception {
final AtomicBoolean aborted = new AtomicBoolean();
ResponseCache.setDefault(new ResponseCache() {
@Override
public CacheResponse get(URI uri, String requestMethod, Map<String, List<String>> requestHeaders) throws IOException {
return null;
}
@Override
public CacheRequest put(URI uri, URLConnection connection) throws IOException {
return new CacheRequest() {
@Override
public void abort() {
aborted.set(true);
}
@Override
public OutputStream getBody() throws IOException {
return null;
}
};
}
});
server.enqueue(new MockResponse().setBody("abcdef"));
server.play();
HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection();
InputStream in = connection.getInputStream();
assertEquals("abc", readAscii(in, 3));
in.close();
// The best behavior is ambiguous, but RI 6 doesn't abort here
assertFalse(aborted.get());
}
Aggregations