public static boolean isStaleCache(Context context, Property[] headers) { String ifNoneMatch = context.getHeaderValue(INM_KEY); String ifModSince = context.getHeaderValue(IMS_KEY); if (ifModSince == null && ifNoneMatch == null) return true; // parse out the data for comparison Date imsDate = (ifModSince == null) ? null : DateUtility.parseDateLoose(ifModSince); long ims = (imsDate == null) ? Long.MIN_VALUE : imsDate.getTime(); // get the local comparison values String etag = null; long lastMod = Long.MAX_VALUE; for (Property header: headers) { if (HttpHeaders.ETAG.equalsIgnoreCase(header.name)) etag = header.value; if (HttpHeaders.LAST_MODIFIED.equalsIgnoreCase(header.name)) { Date d = DateUtility.parseDateLoose(header.value); if (d != null) lastMod = d.getTime(); } } if (ifNoneMatch != null && !ifNoneMatch.equals(etag)) return true; return (ifModSince != null && ims < lastMod); }
public static boolean isStaleCache(Context context, Property[] headers) { String ifNoneMatch = context.getHeaderValue(INM_KEY); String ifModSince = context.getHeaderValue(IMS_KEY); if (ifModSince == null && ifNoneMatch == null) return true; // parse out the data for comparison Date imsDate = (ifModSince == null) ? null : DateUtility.parseDateLoose(ifModSince); long ims = (imsDate == null) ? Long.MIN_VALUE : imsDate.getTime(); // get the local comparison values String etag = null; long lastMod = Long.MAX_VALUE; for (Property header: headers) { if (HttpHeaders.ETAG.equalsIgnoreCase(header.name)) etag = header.value; if (HttpHeaders.LAST_MODIFIED.equalsIgnoreCase(header.name)) { Date d = DateUtility.parseDateLoose(header.value); if (d != null) lastMod = d.getTime(); } } if (ifNoneMatch != null && !ifNoneMatch.equals(etag)) return true; return (ifModSince != null && ims < lastMod); }
@Test public void testConditionalGetETagMethod() throws HttpServiceNotFoundException, GeneralException, IOException, RangeNotSatisfiableException { mockResponseFor("GET"); when(mockClient.get(TEST_URL, true, null, null, "LOL", null, null)) .thenReturn(mockResponse); when(mockContext.getHeaderValue(HttpHeaders.IF_NONE_MATCH)).thenReturn("LOL"); testObj.getExternalContent(mockParams); verify(mockClient).get(TEST_URL, true, null, null, "LOL", null, null); }
@Test public void testConditionalGetRangeMethod() throws HttpServiceNotFoundException, GeneralException, IOException, RangeNotSatisfiableException { mockResponseFor("GET"); when(mockClient.get(TEST_URL, true, null, null, null, null, "LOL")) .thenReturn(mockResponse); when(mockContext.getHeaderValue(HttpHeaders.RANGE)).thenReturn("LOL"); testObj.getExternalContent(mockParams); verify(mockClient).get(TEST_URL, true, null, null, null, null, "LOL"); }
@Test public void testConditionalGetDateMethod() throws HttpServiceNotFoundException, GeneralException, IOException, RangeNotSatisfiableException { mockResponseFor("GET"); when(mockClient.get(TEST_URL, true, null, null, null, "LOL", null)) .thenReturn(mockResponse); when(mockContext.getHeaderValue(HttpHeaders.IF_MODIFIED_SINCE)).thenReturn("LOL"); testObj.getExternalContent(mockParams); verify(mockClient).get(TEST_URL, true, null, null, null, "LOL", null); }
if (headOnly) { response = m_http.head(url, true, user, pass, context.getHeaderValue(HttpHeaders.IF_NONE_MATCH), context.getHeaderValue(HttpHeaders.IF_MODIFIED_SINCE), context.getHeaderValue("Range")); } else { response = m_http.get( url, true, user, pass, context.getHeaderValue(HttpHeaders.IF_NONE_MATCH), context.getHeaderValue(HttpHeaders.IF_MODIFIED_SINCE), context.getHeaderValue("Range"));
if (headOnly) { response = m_http.head(url, true, user, pass, context.getHeaderValue(HttpHeaders.IF_NONE_MATCH), context.getHeaderValue(HttpHeaders.IF_MODIFIED_SINCE), context.getHeaderValue("Range")); } else { response = m_http.get( url, true, user, pass, context.getHeaderValue(HttpHeaders.IF_NONE_MATCH), context.getHeaderValue(HttpHeaders.IF_MODIFIED_SINCE), context.getHeaderValue("Range"));
params.getContext().getHeaderValue(HttpHeaders.RANGE); if (rangeHdr != null) { result.setRange(rangeHdr);;
params.getContext().getHeaderValue(HttpHeaders.RANGE); if (rangeHdr != null) { result.setRange(rangeHdr);;
@Test public void testConditionalHeadETagMethod() throws HttpServiceNotFoundException, GeneralException, IOException, RangeNotSatisfiableException { mockResponseFor("HEAD",304); when(mockClient.head(TEST_URL, true, null, null, "LOL", null, null)) .thenReturn(mockResponse); when(mockContext.getHeaderValue(HttpHeaders.IF_NONE_MATCH)).thenReturn("LOL"); MIMETypedStream out = testObj.getExternalContent(mockParams); verify(mockClient).head(TEST_URL, true, null, null, "LOL", null, null); assertEquals(304, out.getStatusCode()); }
mimeTypedStream = MIMETypedStream.getNotModified(dsHeaders); String rangeHdr = context.getHeaderValue(HttpHeaders.RANGE);
mimeTypedStream = MIMETypedStream.getNotModified(dsHeaders); String rangeHdr = context.getHeaderValue(HttpHeaders.RANGE);