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

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

* Support conditional get for remote archive imports.

parent 9dfa87ba
No related branches found
No related tags found
No related merge requests found
......@@ -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();
......
......@@ -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");
ArchiveIndex index = BlogManager.instance().getArchive().getIndex();
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();
ArchiveIndex index = BlogManager.instance().getArchive().getIndex();
out.write(DataHelper.getUTF8(index.toString()));
out.write(indexUTF8);
out.close();
}
......
......@@ -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 {
......
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