Package com.google.code.http4j

Examples of com.google.code.http4j.Response


    Assert.assertEquals(response.getCharset(), Charset.GBK);
  }
 
  @Test
  public void parseChunkedWithTrailers() throws IOException {
    Response response = parser.parse(new ByteArrayInputStream(chunkedWithTrailers));
    Assert.assertNotNull(response);
    StatusLine statusLine = response.getStatusLine();
    Assert.assertNotNull(statusLine);
    Assert.assertEquals(statusLine.getVersion(), HTTP.HTTP_1_1);
    Assert.assertEquals(statusLine.getStatusCode(), 200);
    Assert.assertEquals(statusLine.getReason(), "OK");
    List<Header> headers = response.getHeaders();
    Assert.assertNotNull(headers);
    Assert.assertEquals(headers.size(), 3);
    Assert.assertTrue(Headers.isChunked(headers));
    Assert.assertEquals(Headers.getValueByName(headers, Headers.CONNECTION), "Keep-Alive");
    byte[] entity = response.getEntity();
    Assert.assertEquals(new String(entity), "Hello World!-from http4j.author:guilin.zhang@hotmail.com");
    Assert.assertEquals(response.getCharset(), Charset.GBK);
  }
View Full Code Here


    Assert.assertEquals(response.getCharset(), Charset.GBK);
  }
 
  @Test
  public void parseNoEntity() throws IOException {
    Response response = parser.parse(new ByteArrayInputStream(noEntity));
    Assert.assertNotNull(response);
    StatusLine statusLine = response.getStatusLine();
    Assert.assertNotNull(statusLine);
    Assert.assertEquals(statusLine.getVersion(), HTTP.HTTP_1_0);
    Assert.assertEquals(statusLine.getStatusCode(), 304);
    Assert.assertEquals(statusLine.getReason(), "Not Modified");
    List<Header> headers = response.getHeaders();
    Assert.assertNotNull(headers);
    Assert.assertEquals(headers.size(), 2);
    int contentLength = Headers.getContentLength(headers);
    Assert.assertEquals(contentLength, 12);
    Assert.assertNull(response.getEntity());
    Assert.assertEquals(response.getCharset(), Charset.UTF_8);
  }
View Full Code Here

  }
 
  @Test
  public void useConnectionPool() throws InterruptedException, IOException, URISyntaxException {
    client.useConnectionPool(false);
    Response response = client.get("http://www.baidu.com/");
    Metrics metrics = response.getMetrics();
    Assert.assertFalse(metrics.getConnectingCost() == 0);
  }
View Full Code Here

  }
 
  @Test(dependsOnMethods = "useConnectionPool")
  public void useDNSCache() throws InterruptedException, IOException, URISyntaxException {
    client.useDNSCache(false);
    Response response = client.get("http://www.baidu.com/");
    Metrics metrics = response.getMetrics();
    Assert.assertTrue(metrics.getDnsLookupCost() > 0);
    Response response2 = client.get("http://www.baidu.com/img/baidu_logo.gif");
    Metrics metrics2 = response2.getMetrics();
    Assert.assertFalse(metrics2.equals(metrics));
    Assert.assertTrue(metrics2.getDnsLookupCost() > 0);
  }
View Full Code Here

TOP

Related Classes of com.google.code.http4j.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.