I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 1962867a authored by ragnarok's avatar ragnarok Committed by zzz
Browse files

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

parent 6019a030
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ public class ArchiveServlet extends HttpServlet {
renderRootIndex(resp);
return;
} else if (path.endsWith(Archive.INDEX_FILE)) {
renderSummary(resp);
renderSummary(req.getHeader("If-None-Match"), resp);
} else if (path.indexOf("export.zip") != -1) {
ExportServlet.export(req, resp);
} else {
......@@ -92,14 +92,18 @@ public class ArchiveServlet extends HttpServlet {
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.setCharacterEncoding("UTF-8");
ArchiveIndex index = BlogManager.instance().getArchive().getIndex();
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");
Hash hash = I2PAppContext.getGlobalContext().sha().calculateHash(indexUTF8);
resp.setHeader("ETag", "\"" + hash.toBase64() + "\"");
resp.setHeader("ETag", newEtag);
OutputStream out = resp.getOutputStream();
out.write(indexUTF8);
out.close();
......
......@@ -336,7 +336,9 @@ public class RemoteArchiveBean {
_statusMessages.add("Fetch of " + HTMLRenderer.sanitizeString(url) + " successful");
_fetchIndexInProgress = false;
ArchiveIndex i = new ArchiveIndex(I2PAppContext.getGlobalContext(), false);
if (!notModified) {
if (notModified) {
_statusMessages.add("Archive unchanged since last fetch.");
} else {
try {
i.load(_archiveFile);
_statusMessages.add("Archive fetched and loaded");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment