use of com.google.mockwebserver.RecordedRequest in project android_frameworks_base by AOSPA.
the class CookiesTest method testCookiesWithNonMatchingCase.
/**
* Test that cookies aren't case-sensitive with respect to hostname.
* http://b/3167208
*/
public void testCookiesWithNonMatchingCase() throws Exception {
// use a proxy so we can manipulate the origin server's host name
server = new MockWebServer();
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=first; Domain=my.t-mobile.com").addHeader("Set-Cookie: b=second; Domain=.T-mobile.com").addHeader("Set-Cookie: c=third; Domain=.t-mobile.com").setBody("This response sets some cookies."));
server.enqueue(new MockResponse().setBody("This response gets those cookies back."));
server.play();
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost("localhost", server.getPort()));
HttpResponse getCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
getCookies.getEntity().consumeContent();
server.takeRequest();
HttpResponse sendCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
sendCookies.getEntity().consumeContent();
RecordedRequest sendCookiesRequest = server.takeRequest();
assertContains(sendCookiesRequest.getHeaders(), "Cookie: a=first; b=second; c=third");
}
use of com.google.mockwebserver.RecordedRequest in project android_frameworks_base by AOSPA.
the class AbstractProxyTest method testParamPreferredOverSystemProperty.
private void testParamPreferredOverSystemProperty(ProxyConfig proxyConfig) throws Exception {
server.enqueue(new MockResponse().setBody("Via request parameter proxy!"));
server.play();
System.setProperty("http.proxyHost", "proxy.foo");
System.setProperty("http.proxyPort", "8080");
HttpClient client = newHttpClient();
HttpGet request = new HttpGet("http://origin.foo/bar");
proxyConfig.configure(server, client, request);
HttpResponse response = client.execute(request);
assertEquals("Via request parameter proxy!", contentToString(response));
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("GET http://origin.foo/bar HTTP/1.1", recordedRequest.getRequestLine());
}
use of com.google.mockwebserver.RecordedRequest in project android_frameworks_base by AOSPA.
the class AbstractProxyTest method testConnectToHttps.
public void testConnectToHttps() throws Exception {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via HTTPS"));
server.play();
HttpClient httpClient = newHttpClient();
SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", sslSocketFactory, server.getPort()));
HttpResponse response = httpClient.execute(new HttpGet("https://localhost:" + server.getPort() + "/foo"));
assertEquals("this response comes via HTTPS", contentToString(response));
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
}
use of com.google.mockwebserver.RecordedRequest in project robovm by robovm.
the class CookiesTest method testCookiesSentIgnoresCase.
public void testCookiesSentIgnoresCase() throws Exception {
CookieHandler.setDefault(new CookieManager() {
@Override
public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) throws IOException {
Map<String, List<String>> result = new HashMap<String, List<String>>();
result.put("COOKIE", Collections.singletonList("Bar=bar"));
result.put("cooKIE2", Collections.singletonList("Baz=baz"));
return result;
}
});
MockWebServer server = new MockWebServer();
try {
// RoboVM note: Modified to call server.shutdown() after test finishes.
server.enqueue(new MockResponse());
server.play();
get(server, "/");
RecordedRequest request = server.takeRequest();
assertContainsAll(request.getHeaders(), "COOKIE: Bar=bar", "cooKIE2: Baz=baz");
assertFalse(request.getHeaders().contains("Quux: quux"));
} finally {
server.shutdown();
}
}
use of com.google.mockwebserver.RecordedRequest in project robovm by robovm.
the class URLConnectionTest method doUpload.
private void doUpload(TransferKind uploadKind, WriteKind writeKind) throws Exception {
int n = 512 * 1024;
server.setBodyLimit(0);
server.enqueue(new MockResponse());
server.play();
HttpURLConnection conn = (HttpURLConnection) server.getUrl("/").openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
if (uploadKind == TransferKind.CHUNKED) {
conn.setChunkedStreamingMode(-1);
} else {
conn.setFixedLengthStreamingMode(n);
}
OutputStream out = conn.getOutputStream();
if (writeKind == WriteKind.BYTE_BY_BYTE) {
for (int i = 0; i < n; ++i) {
out.write('x');
}
} else {
byte[] buf = new byte[writeKind == WriteKind.SMALL_BUFFERS ? 256 : 64 * 1024];
Arrays.fill(buf, (byte) 'x');
for (int i = 0; i < n; i += buf.length) {
out.write(buf, 0, Math.min(buf.length, n - i));
}
}
out.close();
assertEquals(200, conn.getResponseCode());
RecordedRequest request = server.takeRequest();
assertEquals(n, request.getBodySize());
if (uploadKind == TransferKind.CHUNKED) {
assertTrue(request.getChunkSizes().size() > 0);
} else {
assertTrue(request.getChunkSizes().isEmpty());
}
}
Aggregations