Methods Summary |
---|
private void | assertContains(java.util.List headers, java.lang.String header)
@Override void configure(MockWebServer server, HttpClient client, HttpRequest request) {
System.setProperty("proxyHost", "localhost");
System.setProperty("proxyPort", Integer.toString(server.getPort()));
}
@Override void configure(MockWebServer server, HttpClient client, HttpRequest request) {
System.setProperty("http.proxyHost", "localhost");
System.setProperty("http.proxyPort", Integer.toString(server.getPort()));
}
@Override void configure(MockWebServer server, HttpClient client, HttpRequest request) {
System.setProperty("https.proxyHost", "localhost");
System.setProperty("https.proxyPort", Integer.toString(server.getPort()));
}
@Override void configure(MockWebServer server, HttpClient client, HttpRequest request) {
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
new HttpHost("localhost", server.getPort()));
}
@Override void configure(MockWebServer server, HttpClient client, HttpRequest request) {
request.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
new HttpHost("localhost", server.getPort()));
}
assertTrue(headers.toString(), headers.contains(header));
|
private java.lang.String | contentToString(org.apache.http.HttpResponse response)
StringWriter writer = new StringWriter();
char[] buffer = new char[1024];
Reader reader = new InputStreamReader(response.getEntity().getContent());
int length;
while ((length = reader.read(buffer)) != -1) {
writer.write(buffer, 0, length);
}
reader.close();
return writer.toString();
|
protected abstract org.apache.http.client.HttpClient | newHttpClient()
|
private org.apache.http.conn.ssl.SSLSocketFactory | newSslSocketFactory(libcore.javax.net.ssl.TestSSLContext testSSLContext)
// call through to Apache HTTP's non-public SSLSocketFactory constructor
return SSLSocketFactory.class.getConstructor(javax.net.ssl.SSLSocketFactory.class)
.newInstance(testSSLContext.clientContext.getSocketFactory());
|
protected void | tearDown()
System.clearProperty("proxyHost");
System.clearProperty("proxyPort");
System.clearProperty("http.proxyHost");
System.clearProperty("http.proxyPort");
System.clearProperty("https.proxyHost");
System.clearProperty("https.proxyPort");
server.shutdown();
super.tearDown();
|
public void | testClientParamPreferredOverSystemProperty()
testParamPreferredOverSystemProperty(ProxyConfig.CLIENT_PARAMETER);
|
public void | testConnectToHttps()
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());
|
private void | testConnectViaHttpProxyToHttps(android.net.http.AbstractProxyTest$ProxyConfig proxyConfig)
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), true);
server.enqueue(new MockResponse()
.setSocketPolicy(SocketPolicy.UPGRADE_TO_SSL_AT_END)
.clearHeaders());
server.enqueue(new MockResponse()
.setResponseCode(200)
.setBody("this response comes via a secure proxy"));
server.play();
HttpClient httpProxyClient = newHttpClient();
SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
httpProxyClient.getConnectionManager().getSchemeRegistry()
.register(new Scheme("https", sslSocketFactory, 443));
HttpGet request = new HttpGet("https://android.com/foo");
proxyConfig.configure(server, httpProxyClient, request);
HttpResponse response = httpProxyClient.execute(request);
assertEquals("this response comes via a secure proxy", contentToString(response));
RecordedRequest connect = server.takeRequest();
assertEquals("Connect line failure on proxy " + proxyConfig,
"CONNECT android.com:443 HTTP/1.1", connect.getRequestLine());
assertContains(connect.getHeaders(), "Host: android.com");
RecordedRequest get = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", get.getRequestLine());
assertContains(get.getHeaders(), "Host: android.com");
|
public void | testConnectViaHttpProxyToHttpsUsingClientParameter()
testConnectViaHttpProxyToHttps(ProxyConfig.CLIENT_PARAMETER);
|
public void | testConnectViaHttpProxyToHttpsUsingHttpsProxySystemProperty()
testConnectViaHttpProxyToHttps(ProxyConfig.HTTPS_PROXY_SYSTEM_PROPERTY);
|
public void | testConnectViaHttpProxyToHttpsUsingProxySystemProperty()
testConnectViaHttpProxyToHttps(ProxyConfig.PROXY_SYSTEM_PROPERTY);
|
public void | testConnectViaHttpProxyToHttpsUsingRequestParameter()
testConnectViaHttpProxyToHttps(ProxyConfig.REQUEST_PARAMETER);
|
private void | testConnectViaProxy(android.net.http.AbstractProxyTest$ProxyConfig proxyConfig)http://code.google.com/p/android/issues/detail?id=2690
MockResponse mockResponse = new MockResponse()
.setResponseCode(200)
.setBody("this response comes via a proxy");
server.enqueue(mockResponse);
server.play();
HttpClient httpProxyClient = newHttpClient();
HttpGet request = new HttpGet("http://android.com/foo");
proxyConfig.configure(server, httpProxyClient, request);
HttpResponse response = httpProxyClient.execute(request);
assertEquals("this response comes via a proxy", contentToString(response));
RecordedRequest get = server.takeRequest();
assertEquals("GET http://android.com/foo HTTP/1.1", get.getRequestLine());
assertContains(get.getHeaders(), "Host: android.com");
|
public void | testConnectViaProxyUsingClientParameter()
testConnectViaProxy(ProxyConfig.CLIENT_PARAMETER);
|
public void | testConnectViaProxyUsingHttpProxySystemProperty()
testConnectViaProxy(ProxyConfig.HTTP_PROXY_SYSTEM_PROPERTY);
|
public void | testConnectViaProxyUsingProxySystemProperty()We had bugs where proxy system properties weren't being honored.
http://b/3254717
testConnectViaProxy(ProxyConfig.PROXY_SYSTEM_PROPERTY);
|
public void | testConnectViaProxyUsingRequestParameter()
testConnectViaProxy(ProxyConfig.REQUEST_PARAMETER);
|
public void | testExplicitNoProxyCancelsSystemProperty()
server.enqueue(new MockResponse().setBody("Via the origin server!"));
server.play();
System.setProperty("http.proxyHost", "proxy.foo");
System.setProperty("http.proxyPort", "8080");
HttpClient client = newHttpClient();
HttpGet request = new HttpGet(server.getUrl("/bar").toURI());
request.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, ConnRouteParams.NO_HOST);
HttpResponse response = client.execute(request);
assertEquals("Via the origin server!", contentToString(response));
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("GET /bar HTTP/1.1", recordedRequest.getRequestLine());
|
private void | testParamPreferredOverSystemProperty(android.net.http.AbstractProxyTest$ProxyConfig proxyConfig)
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());
|
public void | testRequestParamPreferredOverSystemProperty()
testParamPreferredOverSystemProperty(ProxyConfig.REQUEST_PARAMETER);
|
public void | testRetryWithProxy()
server.enqueue(new MockResponse()
.setSocketPolicy(SocketPolicy.DISCONNECT_AT_START));
server.play();
HttpClient httpProxyClient = newHttpClient();
HttpGet request = new HttpGet("http://android.com/foo");
ProxyConfig.REQUEST_PARAMETER.configure(server, httpProxyClient, request);
try {
httpProxyClient.execute(request);
fail();
} catch (IOException expected) {
}
|