use of org.apache.http.client.HttpClient in project android_frameworks_base by ParanoidAndroid.
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 org.apache.http.client.HttpClient in project android_frameworks_base by ParanoidAndroid.
the class AbstractProxyTest method testConnectViaProxy.
/**
* http://code.google.com/p/android/issues/detail?id=2690
*/
private void testConnectViaProxy(ProxyConfig proxyConfig) throws Exception {
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");
}
use of org.apache.http.client.HttpClient in project android_frameworks_base by ParanoidAndroid.
the class CookiesTest method testCookiesAreNotLogged.
/**
* Test that we don't log potentially sensitive cookie values.
* http://b/3095990
*/
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
// enqueue an HTTP response with a cookie that will be rejected
server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
server.play();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Logger logger = Logger.getLogger("org.apache.http");
StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
logger.addHandler(handler);
try {
HttpClient client = new DefaultHttpClient();
client.execute(new HttpGet(server.getUrl("/").toURI()));
handler.close();
String log = out.toString("UTF-8");
assertTrue(log, log.contains("password"));
assertTrue(log, log.contains("fake.domain"));
assertFalse(log, log.contains("secret"));
} finally {
logger.removeHandler(handler);
}
}
use of org.apache.http.client.HttpClient in project neo4j by neo4j.
the class RetrieveNodeIT method shouldParameteriseUrisInNodeRepresentationWithHostHeaderValue.
@Test
public void shouldParameteriseUrisInNodeRepresentationWithHostHeaderValue() throws Exception {
HttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet(nodeUri);
httpget.setHeader("Accept", "application/json");
httpget.setHeader("Host", "dummy.neo4j.org");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String entityBody = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8);
assertThat(entityBody, containsString("http://dummy.neo4j.org/db/data/node/"));
} finally {
httpclient.getConnectionManager().shutdown();
}
}
use of org.apache.http.client.HttpClient in project neo4j by neo4j.
the class RetrieveNodeIT method shouldParameteriseUrisInNodeRepresentationWithoutHostHeaderUsingRequestUri.
@Test
public void shouldParameteriseUrisInNodeRepresentationWithoutHostHeaderUsingRequestUri() throws Exception {
HttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet(nodeUri);
httpget.setHeader("Accept", "application/json");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String entityBody = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8);
assertThat(entityBody, containsString(nodeUri.toString()));
} finally {
httpclient.getConnectionManager().shutdown();
}
}
Aggregations