* Support conditional get for remote archive imports.

This commit is contained in:
ragnarok
2005-09-30 23:42:28 +00:00
committed by zzz
parent 9dfa87ba47
commit 9a73c6defe
3 changed files with 26 additions and 4 deletions

View File

@@ -166,6 +166,7 @@ public class BlogManager {
public Archive getArchive() { return _archive; }
public File getTempDir() { return _tempDir; }
public File getRootDir() { return _rootDir; }
public List listMyBlogs() {
File files[] = _privKeyDir.listFiles();

View File

@@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import net.i2p.I2PAppContext;
import net.i2p.data.*;
import net.i2p.syndie.*;
import net.i2p.syndie.data.*;
@@ -94,10 +95,13 @@ public class ArchiveServlet extends HttpServlet {
private void renderSummary(HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/plain;charset=utf-8");
//resp.setCharacterEncoding("UTF-8");
resp.setHeader(HEADER_EXPORT_CAPABLE, "true");
OutputStream out = resp.getOutputStream();
ArchiveIndex index = BlogManager.instance().getArchive().getIndex();
out.write(DataHelper.getUTF8(index.toString()));
byte[] indexUTF8 = DataHelper.getUTF8(index.toString());
resp.setHeader(HEADER_EXPORT_CAPABLE, "true");
Hash hash = I2PAppContext.getGlobalContext().sha().calculateHash(indexUTF8);
resp.setHeader("ETag", "\"" + hash.toBase64() + "\"");
OutputStream out = resp.getOutputStream();
out.write(indexUTF8);
out.close();
}

View File

@@ -299,10 +299,27 @@ public class RemoteArchiveBean {
(_proxyHost != null ? " via " + HTMLRenderer.sanitizeString(_proxyHost) + ":" + _proxyPort : ""));
File archiveFile = new File(BlogManager.instance().getTempDir(), user.getBlog().toBase64() + "_remoteArchive.txt");
archiveFile.delete();
Properties etags = new Properties();
try {
etags.load(new FileInputStream(new File(BlogManager.instance().getRootDir(), "etags")));
} catch (Exception exp) {
//ignore
}
EepGet eep = new EepGet(I2PAppContext.getGlobalContext(), ((_proxyHost != null) && (_proxyPort > 0)),
_proxyHost, _proxyPort, 0, archiveFile.getAbsolutePath(), location);
_proxyHost, _proxyPort, 0, archiveFile.getAbsolutePath(), location, etags.getProperty(location));
eep.addStatusListener(new IndexFetcherStatusListener(archiveFile));
eep.fetch();
if (eep.getETag() != null) {
etags.setProperty(location, eep.getETag());
}
try {
etags.store(new FileOutputStream(new File(BlogManager.instance().getRootDir(), "etags")), "etags");
} catch (Exception exp) {
//ignore
}
}
private class IndexFetcherStatusListener implements EepGet.StatusListener {