expectedHeaders.put("content-type", "text/plain");
expectedHeaders.put("cache-control", "public");
expectedHeaders.put("etag", "\"aa\"");
boolean ageFound = false;
for (Iterator iter = content.getHeaders(); iter.hasNext(); ) {
final Header header = (Header) iter.next();
final String name = header.getName().toLowerCase();
if ("age".equals(name) && !ageFound) {
// age must be at least 0
assertTrue(Integer.parseInt(header.getValue()) >= 0);
ageFound = true;
} else {
final String value =
(String) expectedHeaders.remove(name);
assertEquals(value, header.getValue());
}
}
assertTrue(ageFound);
assertTrue(expectedHeaders.isEmpty());
// content is no longer cacheable so hop-by-hop headers should be
// returned with the HTTP content
currentDate = RFC1123.format(new Date());
serverMock.addTransaction(new String[]{
"GET /blah.txt?foo HTTP/1.1",
"If-None-Match: \"aa\"",
UA_STRING,
"Host: " + serverMock.getServerAddress()},
new String[]{
"HTTP/1.0 304 Not Modified",
"Date: " + currentDate,
"Content-Type: text/plain",
"Cache-Control: private",
"Connection: connection-value",
"Keep-Alive: keep-alive-value",
"Proxy-Authenticate: proxy-authenticate-value",
"Proxy-Authorization: proxy-authorization-value",
"TE: te-value",
"Trailers: trailers-value",
"Transfer-Encoding: transfer-encoding-value",
"Upgrade: upgrade-value",
""});
content = (HttpContent) manager.getURLContent(url, null, null);
assertEquals("Content was received", "<p>hello</p>\n",
toString(content.getInputStream()));
assertEquals("HTTP/1.1", content.getHttpVersion());
assertEquals(200, content.getStatusCode());
expectedHeaders = new HashMap();
expectedHeaders.put("date", currentDate);
expectedHeaders.put("content-type", "text/plain");
expectedHeaders.put("cache-control", "private");
expectedHeaders.put("etag", "\"aa\"");
expectedHeaders.put("connection", "connection-value");
expectedHeaders.put("keep-alive", "keep-alive-value");
expectedHeaders.put("proxy-authenticate", "proxy-authenticate-value");
expectedHeaders.put("proxy-authorization", "proxy-authorization-value");
expectedHeaders.put("te", "te-value");
expectedHeaders.put("trailers", "trailers-value");
expectedHeaders.put("transfer-encoding", "transfer-encoding-value");
expectedHeaders.put("upgrade", "upgrade-value");
for (Iterator iter = content.getHeaders(); iter.hasNext(); ) {
final Header header = (Header) iter.next();
final String name = header.getName().toLowerCase();
final String value =
(String) expectedHeaders.remove(name);
assertEquals(value, header.getValue());
}
assertTrue(expectedHeaders.isEmpty());
assertFalse(serverMock.hasTransactions());
}