Author: nextgens Date: 2008-08-14 20:03:23 +0000 (Thu, 14 Aug 2008) New Revision: 21864
Modified: trunk/freenet/src/freenet/clients/http/FProxyToadlet.java trunk/freenet/src/freenet/clients/http/HTTPRequestImpl.java trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java trunk/freenet/src/freenet/support/SizeUtil.java Log: bug #2446: handle the "human" notation for the max-size parameter max-size was already working but not supporting the fancy notations http://127.0.0.1:8888/USK at BFa1voWr5PunINSZ5BGMqFwhkJTiDBBUrOZ0MYBXseg,BOrxeLzUMb6R9tEZzexymY0zyKAmBNvrU4A9Q0tAqu0,AQACAAE/update/1155?type=text/plain&max-size=3.0MiB Modified: trunk/freenet/src/freenet/clients/http/FProxyToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/FProxyToadlet.java 2008-08-14 19:58:24 UTC (rev 21863) +++ trunk/freenet/src/freenet/clients/http/FProxyToadlet.java 2008-08-14 20:03:23 UTC (rev 21864) @@ -55,7 +55,7 @@ // ?force= links become invalid after 2 hours. private static final long FORCE_GRAIN_INTERVAL = 60*60*1000; /** Maximum size for transparent pass-through, should be a config option */ - static int MAX_LENGTH = 2*1024*1024; // 2MB + static long MAX_LENGTH = 2*1024*1024; // 2MB static final URI welcome; static { @@ -444,7 +444,7 @@ String referer = sanitizeReferer(ctx); - handleDownload(ctx, data, ctx.getBucketFactory(), mimeType, requestedMimeType, httprequest.getParam("force", null), httprequest.isParameterSet("forcedownload"), "/", key, maxSize != MAX_LENGTH ? "&max-size="+maxSize : "", referer, true, ctx, core); + handleDownload(ctx, data, ctx.getBucketFactory(), mimeType, requestedMimeType, httprequest.getParam("force", null), httprequest.isParameterSet("forcedownload"), "/", key, maxSize != MAX_LENGTH ? "&max-size="+SizeUtil.formatSizeWithoutSpace(maxSize) : "", referer, true, ctx, core); } catch (FetchException e) { String msg = e.getMessage(); @@ -572,7 +572,7 @@ fileInformationList.addChild("li", l10n("sizeUnknown")); } if(mime != null) { - fileInformationList.addChild("li", L10n.getString("FProxyToadlet."+(finalized ? "mimeType" : "expectedMimeType"), new String[] { "mime" }, new String[] { mime }));; + fileInformationList.addChild("li", L10n.getString("FProxyToadlet."+(finalized ? "mimeType" : "expectedMimeType"), new String[] { "mime" }, new String[] { mime })); } else { fileInformationList.addChild("li", l10n("unknownMIMEType")); } Modified: trunk/freenet/src/freenet/clients/http/HTTPRequestImpl.java =================================================================== --- trunk/freenet/src/freenet/clients/http/HTTPRequestImpl.java 2008-08-14 19:58:24 UTC (rev 21863) +++ trunk/freenet/src/freenet/clients/http/HTTPRequestImpl.java 2008-08-14 20:03:23 UTC (rev 21864) @@ -3,6 +3,7 @@ * http://www.gnu.org/ for further details of the GPL. */ package freenet.clients.http; +import freenet.support.Fields; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.DataInputStream; @@ -619,7 +620,7 @@ } String value = this.getParameterValue(name); try { - return Long.parseLong(value); + return Fields.parseLong(value); } catch (NumberFormatException e) { return defaultValue; } Modified: trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java =================================================================== --- trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java 2008-08-14 19:58:24 UTC (rev 21863) +++ trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java 2008-08-14 20:03:23 UTC (rev 21864) @@ -42,6 +42,7 @@ import freenet.support.api.BooleanCallback; import freenet.support.api.BucketFactory; import freenet.support.api.IntCallback; +import freenet.support.api.LongCallback; import freenet.support.api.StringCallback; import freenet.support.io.ArrayBucketFactory; @@ -93,18 +94,19 @@ ssl = val; throw new InvalidConfigValueException("Cannot change SSL on the fly, please restart freenet"); } + @Override public boolean isReadOnly() { return true; } } - class FProxyPassthruMaxSize extends IntCallback { + class FProxyPassthruMaxSize extends LongCallback { - public Integer get() { + public Long get() { return FProxyToadlet.MAX_LENGTH; } - public void set(Integer val) throws InvalidConfigValueException { + public void set(Long val) throws InvalidConfigValueException { if(val == get()) return; FProxyToadlet.MAX_LENGTH = val; } @@ -121,6 +123,7 @@ throw new InvalidConfigValueException(L10n.getString("cannotChangePortOnTheFly")); // FIXME } + @Override public boolean isReadOnly() { return true; } @@ -412,8 +415,8 @@ }); enableInlinePrefetch = fproxyConfig.getBoolean("enableInlinePrefetch"); - fproxyConfig.register("passthroughMaxSize", 2*1024*1024, configItemOrder++, true, false, "SimpleToadletServer.passthroughMaxSize", "SimpleToadletServer.passthroughMaxSizeLong", new FProxyPassthruMaxSize()); - FProxyToadlet.MAX_LENGTH = fproxyConfig.getInt("passthroughMaxSize"); + fproxyConfig.register("passthroughMaxSize", 2L*1024*1024, configItemOrder++, true, false, "SimpleToadletServer.passthroughMaxSize", "SimpleToadletServer.passthroughMaxSizeLong", new FProxyPassthruMaxSize()); + FProxyToadlet.MAX_LENGTH = fproxyConfig.getLong("passthroughMaxSize"); fproxyConfig.register("allowedHosts", "127.0.0.1,0:0:0:0:0:0:0:1", configItemOrder++, true, true, "SimpleToadletServer.allowedHosts", "SimpleToadletServer.allowedHostsLong", new FProxyAllowedHostsCallback()); Modified: trunk/freenet/src/freenet/support/SizeUtil.java =================================================================== --- trunk/freenet/src/freenet/support/SizeUtil.java 2008-08-14 19:58:24 UTC (rev 21863) +++ trunk/freenet/src/freenet/support/SizeUtil.java 2008-08-14 20:03:23 UTC (rev 21864) @@ -10,7 +10,7 @@ return formatSize(sz, false); } - public static String formatSize(boolean withoutSpace, long sz) { + public static String formatSizeWithoutSpace(long sz) { String[] result = _formatSize(sz); return result[0].concat(result[1]); }
