Search in sources :

Example 56 with HttpGet

use of org.apache.http.client.methods.HttpGet in project nanohttpd by NanoHttpd.

the class CookieIntegrationTest method testServerReceivesMultipleCookiesSentFromClient.

@Test
public void testServerReceivesMultipleCookiesSentFromClient() throws Exception {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_YEAR, 100);
    Date date = calendar.getTime();
    BasicClientCookie clientCookie0 = new BasicClientCookie("name0", "value0");
    BasicClientCookie clientCookie1 = new BasicClientCookie("name1", "value1");
    BasicClientCookie clientCookie2 = new BasicClientCookie("name2", "value2");
    BasicClientCookie clientCookie3 = new BasicClientCookie("name3", "value3");
    clientCookie0.setExpiryDate(date);
    clientCookie0.setDomain("localhost");
    clientCookie1.setExpiryDate(date);
    clientCookie1.setDomain("localhost");
    clientCookie2.setExpiryDate(date);
    clientCookie2.setDomain("localhost");
    clientCookie3.setExpiryDate(date);
    clientCookie3.setDomain("localhost");
    this.httpclient.getCookieStore().addCookie(clientCookie0);
    this.httpclient.getCookieStore().addCookie(clientCookie1);
    this.httpclient.getCookieStore().addCookie(clientCookie2);
    this.httpclient.getCookieStore().addCookie(clientCookie3);
    HttpGet httpget = new HttpGet("http://localhost:8192/");
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    this.httpclient.execute(httpget, responseHandler);
    assertEquals(4, this.testServer.cookiesReceived.size());
}
Also used : Calendar(java.util.Calendar) HttpGet(org.apache.http.client.methods.HttpGet) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Date(java.util.Date) Test(org.junit.Test)

Example 57 with HttpGet

use of org.apache.http.client.methods.HttpGet in project nanohttpd by NanoHttpd.

the class CookieIntegrationTest method testNoCookies.

@Test
public void testNoCookies() throws Exception {
    HttpGet httpget = new HttpGet("http://localhost:8192/");
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    this.httpclient.execute(httpget, responseHandler);
    CookieStore cookies = this.httpclient.getCookieStore();
    assertEquals(0, cookies.getCookies().size());
}
Also used : CookieStore(org.apache.http.client.CookieStore) HttpGet(org.apache.http.client.methods.HttpGet) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) Test(org.junit.Test)

Example 58 with HttpGet

use of org.apache.http.client.methods.HttpGet in project nanohttpd by NanoHttpd.

the class GZipIntegrationTest method contentShouldNotBeGzippedIfContentLengthIsAddedManually.

@Test
public void contentShouldNotBeGzippedIfContentLengthIsAddedManually() throws IOException {
    testServer.response = Response.newFixedLengthResponse("This is a test");
    testServer.response.addHeader("Content-Length", "" + ("This is a test".getBytes("UTF-8").length));
    HttpGet request = new HttpGet("http://localhost:8192/");
    request.addHeader("Accept-encoding", "gzip");
    HttpResponse response = httpclient.execute(request);
    Header contentEncoding = response.getFirstHeader("content-encoding");
    assertNull("Content-Encoding should not be set when manually setting content-length", contentEncoding);
    assertEquals("This is a test", EntityUtils.toString(response.getEntity()));
}
Also used : Header(org.apache.http.Header) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 59 with HttpGet

use of org.apache.http.client.methods.HttpGet in project nanohttpd by NanoHttpd.

the class GZipIntegrationTest method chunkedContentIsEncodedProperly.

@Test
public void chunkedContentIsEncodedProperly() throws IOException {
    InputStream data = new ByteArrayInputStream("This is a test".getBytes("UTF-8"));
    testServer.response = Response.newChunkedResponse(Status.OK, "text/plain", data);
    HttpGet request = new HttpGet("http://localhost:8192/");
    request.addHeader("Accept-encoding", "gzip");
    HttpResponse response = new DecompressingHttpClient(httpclient).execute(request);
    assertEquals("This is a test", EntityUtils.toString(response.getEntity()));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DecompressingHttpClient(org.apache.http.impl.client.DecompressingHttpClient) Test(org.junit.Test)

Example 60 with HttpGet

use of org.apache.http.client.methods.HttpGet in project nanohttpd by NanoHttpd.

the class GZipIntegrationTest method contentLengthShouldBeRemovedFromZippedResponses.

@Test
public void contentLengthShouldBeRemovedFromZippedResponses() throws IOException {
    testServer.response = Response.newFixedLengthResponse("This is a test");
    HttpGet request = new HttpGet("http://localhost:8192/");
    request.addHeader("Accept-encoding", "gzip");
    HttpResponse response = httpclient.execute(request);
    Header contentLength = response.getFirstHeader("content-length");
    assertNull("Content-Length should not be set when gzipping response", contentLength);
}
Also used : Header(org.apache.http.Header) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Aggregations

HttpGet (org.apache.http.client.methods.HttpGet)1143 HttpResponse (org.apache.http.HttpResponse)717 Test (org.junit.Test)504 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)242 TestHttpClient (io.undertow.testutils.TestHttpClient)239 IOException (java.io.IOException)200 HttpClient (org.apache.http.client.HttpClient)185 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)179 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)176 HttpEntity (org.apache.http.HttpEntity)152 Header (org.apache.http.Header)133 InputStream (java.io.InputStream)103 URI (java.net.URI)83 JsonNode (com.fasterxml.jackson.databind.JsonNode)68 ArrayList (java.util.ArrayList)60 MockResponse (com.google.mockwebserver.MockResponse)54 HttpPost (org.apache.http.client.methods.HttpPost)54 Deployment (org.activiti.engine.test.Deployment)49 ClientProtocolException (org.apache.http.client.ClientProtocolException)46 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)45