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());
}
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());
}
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()));
}
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()));
}
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);
}
Aggregations