* Actually implement the bit that returns a 304 if archive.txt hasn't changed.

This commit is contained in:
ragnarok
2005-10-03 02:54:34 +00:00
committed by zzz
parent 6019a03029
commit 1962867ad9
2 changed files with 11 additions and 5 deletions

View File

@ -24,7 +24,7 @@ public class ArchiveServlet extends HttpServlet {
renderRootIndex(resp); renderRootIndex(resp);
return; return;
} else if (path.endsWith(Archive.INDEX_FILE)) { } else if (path.endsWith(Archive.INDEX_FILE)) {
renderSummary(resp); renderSummary(req.getHeader("If-None-Match"), resp);
} else if (path.indexOf("export.zip") != -1) { } else if (path.indexOf("export.zip") != -1) {
ExportServlet.export(req, resp); ExportServlet.export(req, resp);
} else { } else {
@ -92,14 +92,18 @@ public class ArchiveServlet extends HttpServlet {
public static final String HEADER_EXPORT_CAPABLE = "X-Syndie-Export-Capable"; public static final String HEADER_EXPORT_CAPABLE = "X-Syndie-Export-Capable";
private void renderSummary(HttpServletResponse resp) throws ServletException, IOException { private void renderSummary(String etag, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/plain;charset=utf-8"); resp.setContentType("text/plain;charset=utf-8");
//resp.setCharacterEncoding("UTF-8"); //resp.setCharacterEncoding("UTF-8");
ArchiveIndex index = BlogManager.instance().getArchive().getIndex(); ArchiveIndex index = BlogManager.instance().getArchive().getIndex();
byte[] indexUTF8 = DataHelper.getUTF8(index.toString()); byte[] indexUTF8 = DataHelper.getUTF8(index.toString());
String newEtag = "\"" + I2PAppContext.getGlobalContext().sha().calculateHash(indexUTF8).toBase64() + "\"";
if (etag != null && etag.equals(newEtag)) {
resp.sendError(304, "Archive not modified");
return;
}
resp.setHeader(HEADER_EXPORT_CAPABLE, "true"); resp.setHeader(HEADER_EXPORT_CAPABLE, "true");
Hash hash = I2PAppContext.getGlobalContext().sha().calculateHash(indexUTF8); resp.setHeader("ETag", newEtag);
resp.setHeader("ETag", "\"" + hash.toBase64() + "\"");
OutputStream out = resp.getOutputStream(); OutputStream out = resp.getOutputStream();
out.write(indexUTF8); out.write(indexUTF8);
out.close(); out.close();

View File

@ -336,7 +336,9 @@ public class RemoteArchiveBean {
_statusMessages.add("Fetch of " + HTMLRenderer.sanitizeString(url) + " successful"); _statusMessages.add("Fetch of " + HTMLRenderer.sanitizeString(url) + " successful");
_fetchIndexInProgress = false; _fetchIndexInProgress = false;
ArchiveIndex i = new ArchiveIndex(I2PAppContext.getGlobalContext(), false); ArchiveIndex i = new ArchiveIndex(I2PAppContext.getGlobalContext(), false);
if (!notModified) { if (notModified) {
_statusMessages.add("Archive unchanged since last fetch.");
} else {
try { try {
i.load(_archiveFile); i.load(_archiveFile);
_statusMessages.add("Archive fetched and loaded"); _statusMessages.add("Archive fetched and loaded");