예제 #1
0
  /**
   * plain HTTP response, without transfer/content-encoding.
   *
   * @throws Exception
   */
  public void testPlainHttpRecord() throws Exception {
    String payload = "hogehogehogehogehoge";
    WARCRecordInfo recinfo = TestWARCRecordInfo.createHttpResponse(payload);
    recinfo.setMimetype("text/plain");
    TestARCReader ar = new TestARCReader(recinfo);
    ARCRecord rec = ar.get(0);
    ArcResource res = new ArcResource(rec, ar);
    res.parseHeaders();

    assertEquals("statusCode", 200, res.getStatusCode());
    assertEquals("content-type", "text/plain", res.getHeader("Content-Type"));
    byte[] buf = new byte[payload.getBytes().length + 1];
    int n = res.read(buf);
    assertEquals("content length", buf.length - 1, n);

    res.close();
  }
예제 #2
0
  /**
   * gzip-compressed HTTP response.
   *
   * @throws Exception
   */
  public void testCompressedHttpRecord() throws Exception {
    String payload = "hogehogehogehogehoge";
    String ctype = "text/plain";
    WARCRecordInfo recinfo =
        new TestWARCRecordInfo(
            TestWARCRecordInfo.buildCompressedHttpResponseBlock(ctype, payload.getBytes()));
    recinfo.setMimetype(ctype);
    TestARCReader ar = new TestARCReader(recinfo);
    ARCRecord rec = ar.get(0);
    ArcResource res = new ArcResource(rec, ar);
    res.parseHeaders();

    assertEquals("statusCode", 200, res.getStatusCode());
    assertEquals("content-type", ctype, res.getHeader("Content-Type"));

    Resource zres = TextReplayRenderer.decodeResource(res);
    assertTrue("wrapped with GzipDecodingResource", (zres instanceof GzipDecodingResource));

    byte[] buf = new byte[payload.getBytes().length + 1];
    int n = zres.read(buf);
    assertEquals("content length", buf.length - 1, n);

    res.close();
  }