public void testGetAlreadyExpired() throws Exception {
IHttpRequestHandler reqHdl = new IHttpRequestHandler() {
public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
HttpResponse resp = new HttpResponse(200, "text/plain", "test");
resp.setHeader("Expires", "Fri, 30 Oct 2011 14:19:41 GMT");
resp.setHeader("Cache-Control", "public, max-age=1");
exchange.send(resp);
}
};
HttpServer server = new HttpServer(reqHdl);
server.start();
HttpClient httpClient = new HttpClient();
httpClient.setCacheMaxSizeKB(100);
IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
Assert.assertEquals(200, resp.getStatus());
Assert.assertEquals("test", resp.getBody().readString());
Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
QAUtil.sleep(2000);
resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
Assert.assertEquals(200, resp.getStatus());
Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
Assert.assertEquals("test", resp.getBody().readString());
QAUtil.sleep(1000);
Assert.assertEquals(0, httpClient.getNumCacheHit());
Assert.assertEquals(2, httpClient.getNumCacheMiss());