@Override public void parseHeaders() throws IOException { // currently this is not supposed to be used. // it is assumed parseHeaders() is already // called on each Resource. headersResource.parseHeaders(); payloadResource.parseHeaders(); } @Override
@Override public void parseHeaders() throws IOException { // currently this is not supposed to be used. // it is assumed parseHeaders() is already // called on each Resource. headersResource.parseHeaders(); payloadResource.parseHeaders(); } @Override
protected void setupResource(byte[] payload) throws IOException { TestWARCRecordInfo recinfo = TestWARCRecordInfo.createHttpResponse("text/html", payload); TestWARCReader ar = new TestWARCReader(recinfo); WARCRecord rec = ar.get(0); resource = new WarcResource(rec, ar); resource.parseHeaders(); }
public void testRenderResource_BasicCapture() throws Exception { final String ct = "image/gif"; WARCRecordInfo recinfo = TestWARCRecordInfo.createHttpResponse(ct, TestWARCRecordInfo.PAYLOAD_GIF); TestWARCReader ar = new TestWARCReader(recinfo); WARCRecord rec = ar.get(0); Resource payloadResource = new WarcResource(rec, ar); payloadResource.parseHeaders(); Resource headersResource = payloadResource; TestServletOutputStream servletOutput = new TestServletOutputStream(); response.setStatus(200); EasyMock.expect(response.getOutputStream()).andReturn(servletOutput); response.setHeader("Content-Type", ct); // ??? RedirectRewritingHttpHeaderProcessor drops Content-Length header. is this really // it is supposed to do? //response.setHeader("Content-Length", Integer.toString(payloadBytes.length)); response.setHeader(EasyMock.<String>notNull(), EasyMock.<String>notNull()); EasyMock.expectLastCall().anyTimes(); EasyMock.replay(response); cut.renderResource(request, response, wbRequest, result, headersResource, payloadResource, uriConverter, results); EasyMock.verify(response); byte[] content = servletOutput.getBytes(); assertTrue("servlet output", Arrays.equals(TestWARCRecordInfo.PAYLOAD_GIF, content)); }
WARCRecord rec = ar.get(0); Resource payloadResource = new WarcResource(rec, ar); payloadResource.parseHeaders(); Resource headersResource = payloadResource;
WARCRecord rec = ar.get(0); Resource payloadResource = new WarcResource(rec, ar); payloadResource.parseHeaders();
/** * uncompressed, but chunked-encoded HTTP response * @throws Exception */ public void testPlainChunkedHttpRecord() throws Exception { String payload = "hogehogehogehogehoge"; WARCRecordInfo recinfo = new TestWARCRecordInfo( TestWARCRecordInfo.buildHttpResponseBlock("200 OK", "text/plain", payload.getBytes("UTF-8"), true)); Resource res = createResource(recinfo); 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(); }
/** * plain HTTP response (without any transfer/content-encoding) * @throws Exception */ public void testPlainHttpRecord() throws Exception { String payload = "hogehogehogehogehoge"; WARCRecordInfo recinfo = TestWARCRecordInfo.createHttpResponse(payload); Resource res = createResource(recinfo); 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(); } /**
/** * resource record, typically used for archiving ftp fetches. * @throws Exception */ public void testResourceRecord() throws Exception { final String ct = "text/plain"; final byte[] block = "blahblahblah\n".getBytes(); WARCRecordInfo recinfo = new TestWARCRecordInfo(block); recinfo.setType(WARCRecordType.resource); recinfo.setUrl("ftp://ftp.example.com/afile.txt"); recinfo.setMimetype(ct); Resource res = createResource(recinfo); res.parseHeaders(); int scode = res.getStatusCode(); assertEquals("statusCode", 200, scode); Map<String, String> headers = res.getHttpHeaders(); assertNotNull("headers", headers); assertEquals("content-type", ct, res.getHeader("Content-Type")); // must have Date header, in HTTP Date format. String date = res.getHeader("Date"); assertNotNull("has date header", date); new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH).parse(date); res.close(); }
/** * 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())); Resource res = createResource(recinfo); 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(); }
/** * gzip-compressed, chunked-encoded HTTP response. * @throws Exception */ public void testCompressedChunkedHttpRecord() throws Exception { String payload = "hogehogehogehogehoge"; String ctype = "text/plain"; WARCRecordInfo recinfo = new TestWARCRecordInfo( TestWARCRecordInfo.buildCompressedHttpResponseBlock(ctype, payload.getBytes(), true)); Resource res = createResource(recinfo); 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(); }
WARCRecord rec = ar.get(0); Resource payloadResource = new WarcResource(rec, ar); payloadResource.parseHeaders();
WARCRecord rec = ar.get(0); Resource payloadResource = new WarcResource(rec, ar); payloadResource.parseHeaders();
WARCRecord rec = ar.get(0); Resource payloadResource = new WarcResource(rec, ar); payloadResource.parseHeaders();
WARCRecordInfo recinfo = TestWARCRecordInfo.createRevisitHttpResponse(ct, 1345, false); Resource res = createResource(recinfo); res.parseHeaders();
Resource res = createResource(recinfo); res.parseHeaders();
/** * new, current revisit record, which has just HTTP response line and * headers part of the capture. * <p>Expectations: * TextReplayRender receives revisit WarcResource as {@code httpHeaderResource}, * and calls following methods on it:</p> * <ul> * <li>{@link WarcResource#getStatusCode()}</li> * <li>{@link WarcResource#getHttpHeaders()} (ok to return null)</li> * </ul> * @throws Exception */ public void testRevisitRecord() throws Exception { final String ct = "text/html"; WARCRecordInfo recinfo = TestWARCRecordInfo.createRevisitHttpResponse(ct, 1345); Resource res = createResource(recinfo); res.parseHeaders(); // these are from this record. assertEquals("statusCode", 200, res.getStatusCode()); assertEquals("content-type", ct, res.getHeader("Content-Type")); StandardCharsetDetector csd = new StandardCharsetDetector(); // assuming WaybackRequest (3rd parameter) is not used in getCharset() csd.getCharset(res, res, null); res.close(); }
public void testUrlAgnosticRevisitRecord() throws Exception { final String ctype = "text/html"; WARCRecordInfo recinfo = TestWARCRecordInfo .createUrlAgnosticRevisitHttpResponse(ctype, 1345); Resource res = createResource(recinfo); res.parseHeaders(); // these are from this record. assertEquals("statusCode", 200, res.getStatusCode()); assertEquals("content-type", ctype, res.getHeader("Content-Type")); assertEquals("http://example.com/", res.getRefersToTargetURI()); assertEquals("20140101101010", res.getRefersToDate()); StandardCharsetDetector csd = new StandardCharsetDetector(); // assuming WaybackRequest (3rd parameter) is not used in getCharset() csd.getCharset(res, res, null); res.close(); }