public void testGetWithExpireHeaderAndPOST() 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");
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(1000);
resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
Assert.assertEquals(200, resp.getStatus());
Assert.assertTrue(resp.getHeader(CacheHandler.XHEADER_NAME).startsWith("HIT"));
Assert.assertEquals("test", resp.getBody().readString());
QAUtil.sleep(1000);
resp = httpClient.call(new PostRequest("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);
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());
Assert.assertEquals(1, httpClient.getNumCacheHit());
Assert.assertEquals(2, httpClient.getNumCacheMiss());