/** * Add {@code Memento-Datetime} header, and full {@code Link} header if * {@code wbr} is not a Memento Timegate request. * @param response * @param results * @param result * @param wbr * @deprecated 1.8.1 2014-09-12 use * {@link #addMementoDatetimeHeader(HttpServletResponse, CaptureSearchResult)} * and * {@link #addLinkHeader(HttpServletResponse, CaptureSearchResults, WaybackRequest, boolean, boolean)} */ public static void addMementoHeaders(HttpServletResponse response, CaptureSearchResults results, CaptureSearchResult result, WaybackRequest wbr) { response.setHeader(MEMENTO_DATETIME, formatLinkDate(results.getClosest().getCaptureDate())); if (!wbr.isMementoTimegate()) { response.setHeader(LINK, generateMementoLinkHeaders(results, wbr, true, true)); } }
/** * Add {@code Memento-Datetime} header, and full {@code Link} header if * {@code wbr} is not a Memento Timegate request. * @param response * @param results * @param result * @param wbr * @deprecated 1.8.1 2014-09-12 use * {@link #addMementoDatetimeHeader(HttpServletResponse, CaptureSearchResult)} * and * {@link #addLinkHeader(HttpServletResponse, CaptureSearchResults, WaybackRequest, boolean, boolean)} */ public static void addMementoHeaders(HttpServletResponse response, CaptureSearchResults results, CaptureSearchResult result, WaybackRequest wbr) { response.setHeader(MEMENTO_DATETIME, formatLinkDate(results.getClosest().getCaptureDate())); if (!wbr.isMementoTimegate()) { response.setHeader(LINK, generateMementoLinkHeaders(results, wbr, true, true)); } }
CaptureSearchResults captureResults, CaptureSearchResult closest) throws BetterRequestException { if (wbRequest.getReplayTimestamp().startsWith(closest.getCaptureTimestamp()) && !wbRequest.isMementoTimegate()) { if (fixedEmbeds && !wbRequest.isMementoTimegate() && isWaybackReferer(wbRequest, this.getReplayPrefix())) { httpResponse.setHeader("Content-Location", betterURI); return;
CaptureSearchResults captureResults, CaptureSearchResult closest) throws BetterRequestException { if (wbRequest.getReplayTimestamp().startsWith(closest.getCaptureTimestamp()) && !wbRequest.isMementoTimegate()) { if (fixedEmbeds && !wbRequest.isMementoTimegate() && isWaybackReferer(wbRequest, this.getReplayPrefix())) { httpResponse.setHeader("Content-Location", betterURI); return;
@Override public void generateResponse(HttpServletResponse response, WaybackRequest wbRequest) { AccessPoint accessPoint = wbRequest.getAccessPoint(); String replayURL = accessPoint.getUriConverter().makeReplayURI( ArchivalUrl.getDateSpec(wbRequest, timestamp), targetURI); response.setStatus(HttpServletResponse.SC_FOUND); response.setHeader("Location", replayURL); if (wbRequest.isMementoEnabled()) { // both URI-G redirect response and intermediate resource response // MUST NOT have Memento-Datetime header. if (wbRequest.isMementoTimegate()) { // URI-G redirect response if (accessPoint.getMementoHandler() != null) { accessPoint.getMementoHandler().addTimegateHeaders(response, captures, wbRequest, true); } else { MementoUtils.addTimegateHeaders(response, captures, wbRequest, true); } } else { // intermediate resource that redirects to URL-M // should the second argument wbRequest.getRequestUrl() or this.targetURI? // there are different approaches in the code. MementoUtils.addOrigHeader(response, this.targetURI); } } }
@Override public void generateResponse(HttpServletResponse response, WaybackRequest wbRequest) { AccessPoint accessPoint = wbRequest.getAccessPoint(); String replayURL = accessPoint.getUriConverter().makeReplayURI( ArchivalUrl.getDateSpec(wbRequest, timestamp), targetURI); response.setStatus(HttpServletResponse.SC_FOUND); response.setHeader("Location", replayURL); if (wbRequest.isMementoEnabled()) { // both URI-G redirect response and intermediate resource response // MUST NOT have Memento-Datetime header. if (wbRequest.isMementoTimegate()) { // URI-G redirect response if (accessPoint.getMementoHandler() != null) { accessPoint.getMementoHandler().addTimegateHeaders(response, captures, wbRequest, true); } else { MementoUtils.addTimegateHeaders(response, captures, wbRequest, true); } } else { // intermediate resource that redirects to URL-M // should the second argument wbRequest.getRequestUrl() or this.targetURI? // there are different approaches in the code. MementoUtils.addOrigHeader(response, this.targetURI); } } }
assertFalse(wbRequest.isMementoTimegate());
assertFalse(wbRequest.isMementoTimegate());
public void testProtocolRelative() throws Exception { acceptDatetime = "Mon, 27 Oct 2014 20:36:02 GMT"; accessPoint.setEnableMemento(true); setupRequest("//example.com/"); EasyMock.replay(request); try { WaybackRequest wbr = cut.parse(request, accessPoint); assertNotNull(wbr); assertTrue(wbr.isReplayRequest()); assertTrue(wbr.isMementoTimegate()); assertEquals("http://example.com/", wbr.getRequestUrl()); assertEquals("20141027203602", wbr.getReplayTimestamp()); } catch (NullPointerException ex) { // it fails with NullPointerException currently. System.err.println("needs fix"); ex.printStackTrace(); } }
public void testAcceptDatetime() throws Exception { acceptDatetime = "Mon, 27 Oct 2014 20:36:02 GMT"; accessPoint.setEnableMemento(true); setupRequest("http://example.com/"); EasyMock.replay(request); WaybackRequest wbr = cut.parse(request, accessPoint); assertNotNull(wbr); assertTrue(wbr.isReplayRequest()); assertTrue(wbr.isMementoTimegate()); assertEquals("http://example.com/", wbr.getRequestUrl()); assertEquals("20141027203602", wbr.getReplayTimestamp()); }
/** * Accept-Datetime is ignored unless {@code enabledMemento} is {@code true}. * @throws Exception */ public void testMementoDisabled() throws Exception { acceptDatetime = "Mon, 27 Oct 2014 20:36:02 GMT"; accessPoint.setEnableMemento(false); setupRequest("http://example.com/"); EasyMock.replay(request); WaybackRequest wbr = cut.parse(request, accessPoint); assertNotNull(wbr); assertTrue(wbr.isReplayRequest()); assertFalse(wbr.isMementoTimegate()); assertEquals("http://example.com/", wbr.getRequestUrl()); assertNotNull(wbr.getReplayTimestamp()); assertFalse("20141027203602".equals(wbr.getReplayTimestamp())); }
/** * Alternate header {@code Accept-Timestamp} is in DT14 format. * @throws Exception */ public void testAcceptTimestamp() throws Exception { acceptTimestamp = "20141027203602"; accessPoint.setEnableMemento(true); setupRequest("http://example.com/"); EasyMock.replay(request); WaybackRequest wbr = cut.parse(request, accessPoint); assertNotNull(wbr); assertTrue(wbr.isReplayRequest()); assertTrue(wbr.isMementoTimegate()); assertEquals("http://example.com/", wbr.getRequestUrl()); assertEquals("20141027203602", wbr.getReplayTimestamp()); }
/** * invalid Accept-Timestamp is simply ignored * @throws Exception */ public void testAcceptTimestamp_invalid() throws Exception { // Valid HTTP Date, but invalid for Accept-Timestamp acceptTimestamp = "Mon, 27 Oct 2014 20:36:02 GMT"; accessPoint.setEnableMemento(true); setupRequest("http://example.com/"); EasyMock.replay(request); WaybackRequest wbr = cut.parse(request, accessPoint); assertNotNull(wbr); assertTrue(wbr.isReplayRequest()); assertTrue(wbr.isMementoTimegate()); assertEquals("http://example.com/", wbr.getRequestUrl()); assertNotNull(wbr.getReplayTimestamp()); }
/** * Invalid Accept-Datetime is simply ignored if valid * Accept-Timestamp is present. * @throws Exception */ public void testAcceptDate_invalidWithTimestamp() throws Exception { acceptDatetime = "2014-10-27 20:36:02"; acceptTimestamp = "20141027203602"; accessPoint.setEnableMemento(true); setupRequest("http://example.com/"); EasyMock.replay(request); WaybackRequest wbr = cut.parse(request, accessPoint); assertNotNull(wbr); assertTrue(wbr.isReplayRequest()); assertTrue(wbr.isMementoTimegate()); assertEquals("http://example.com/", wbr.getRequestUrl()); assertEquals("20141027203602", wbr.getReplayTimestamp()); }
if (wbRequest.isMementoTimegate()) {
if (wbRequest.isMementoTimegate()) {
assertNotNull(wbr); assertTrue(wbr.isReplayRequest()); assertTrue(wbr.isMementoTimegate()); assertFalse(wbr.isBestLatestReplayRequest()); assertEquals(EXPECTED_START_TIMESTAMP, wbr.getStartTimestamp());