this is a patch which almost does the containers stuff flamewared above. specifically, it does /key//file.jar///index.html like stuff.
It doesn't do two important things yet, and hence shouldn't be commited yet -
it's presented here as an exercise in asking what the concensus was on these two
things:
a) caching - seeking through the jar for 100+ files is going to be teh pains.
it's of course fast on my test sites, but they're all small.
b) metadata - how should this be specified in this scenario? should there be
file.metadata files in the jar? should it be in the manifest of the upstream
key (i consider this a bad way of doing thigns, btw, but it would be faster)?
is it enough just to have freenet work it out from the extension in this case?
(no, it's actually not). Is there another way that I havn't through of?
(yes :-p)
Attempting to actualyl use this will result in bad things, most likely. Like
the old release notes said, this isn't supposed to work, and if it does, then
ergo it isn't doing what it's supposed to, and hence isn't working :)
it worked for me, but that means nothing :).
-- fish
Index: src/freenet/client/http/FproxyServlet.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/client/http/FproxyServlet.java,v
retrieving revision 1.96
diff -u -3 -p -u -r1.96 FproxyServlet.java
--- src/freenet/client/http/FproxyServlet.java 21 Jun 2003 11:43:30 -0000 1.96
+++ src/freenet/client/http/FproxyServlet.java 26 Jun 2003 15:53:11 -0000
@@ -21,6 +21,8 @@ import freenet.node.Node;
import java.io.*;
import java.net.*;
import java.util.*;
+import java.util.jar.*;
+import java.util.zip.*;
import javax.servlet.*;
import javax.servlet.http.*;
@@ -364,6 +366,7 @@ public class FproxyServlet extends HttpS
// Query parameters
String key = null;
+ String containerFile = null;
String queryKey = null;
String queryForce = null;
String queryHtl = null;
@@ -528,8 +531,19 @@ public class FproxyServlet extends HttpS
"the nodeinfo status page as required.");
}
-
+ // Okay, we've got this far, see if the key is a container request
+ String originalKey=key;
+ String [] splitkey=key.split("///");
+ if(splitkey.length==2) {
+ key=splitkey[0];
+ containerFile=splitkey[1];
+
+ }
+ else if (splitkey.length>2) {
+ // FIXME: throw an error at the user
+ }
+
// Do request, following redirects as necessary.
// REDFLAG: where does data get freed?
data = bucketFactory.makeBucket(-1);
@@ -579,6 +593,64 @@ public class FproxyServlet extends HttpS
return;
}
+
+ // Check if we need to de-container this file
+ // FIXME: cache jar's
+ if(containerFile != null)
+ {
+ InputStream myIs=data.getInputStream();
+ JarInputStream myJis=new JarInputStream(myIs);
+ // because we don't have access to a File object,
+ // we have to skip through until we hit our filename...
+ JarEntry ent=null;
+ boolean done=false;
+ do
+ {
+ try {
+ ent=myJis.getNextJarEntry();
+ if(ent==null)
+ {
+ // Return a "data not in
manifest" error
+ writeErrorMessage(new
KeyNotInManifestException(originalKey) , resp,
+ null, originalKey, uri,
htlUsed, queryDate,
+ queryMime, queryForce,
tryNum+1);
+ return;
+ }
+
if(ent.getName().equalsIgnoreCase(containerFile))
+ {
+ Bucket
t=bucketFactory.makeBucket(-1);
+ BufferedOutputStream
myOs=new BufferedOutputStream(t.getOutputStream());
+ BufferedInputStream
mybj=new BufferedInputStream(myJis);
+ int tt;
+ do
+ {
+
tt=mybj.read();
+
if(tt== -1)
+ {
+
data=t;
+
done=true;
+ }
+ else
+ {
+
myOs.write(tt);
+ }
+
+ } while(!done);
+ }
+ } catch (ZipException e) {
+ // Return a "data not in
manifest" error
+ writeErrorMessage(new
KeyNotInManifestException(originalKey), resp,
+ null, originalKey, uri,
htlUsed, queryDate,
+ queryMime, queryForce,
tryNum+1);
+ return;
+ }
+ } while(ent!=null && !done);
+ }
+
+ // Reset the key for the rest - the fetch is over, and this makes
+ // later things happier
+ key=originalKey;
+
// Find content type, in descending order of preference:
// x 1. specified in query parameters
// x 2. specified in metadata
@@ -601,10 +673,13 @@ public class FproxyServlet extends HttpS
mimeType = queryMime;
}
- // Try to read the mime type out of the metadata
- if ((mimeType == null) && (r.getMetadata() != null)) {
- mimeType = r.getMetadata().getMimeType(null);
- }
+ if(containerFile==null)
+ {
+ // Try to read the mime type out of the metadata
+ if ((mimeType == null) && (r.getMetadata() != null)) {
+ mimeType = r.getMetadata().getMimeType(null);
+ }
+ }
// If that doesn't work guess it from the extension
// on the key name.
pgp00000.pgp
Description: PGP signature
