From 4c603b216ed1ba207e8b12538a69971f2dff520b Mon Sep 17 00:00:00 2001 From: reger Date: Wed, 22 Jan 2014 21:23:32 +0100 Subject: [PATCH] optimize parse ServerSideInclude --- .../http/servlets/YaCyDefaultServlet.java | 51 +++++++++---------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/source/net/yacy/http/servlets/YaCyDefaultServlet.java b/source/net/yacy/http/servlets/YaCyDefaultServlet.java index 70f17fd9d..14c235f43 100644 --- a/source/net/yacy/http/servlets/YaCyDefaultServlet.java +++ b/source/net/yacy/http/servlets/YaCyDefaultServlet.java @@ -50,6 +50,7 @@ import net.yacy.cora.date.GenericFormatter; import net.yacy.cora.document.analysis.Classification; import net.yacy.cora.protocol.HeaderFramework; import net.yacy.cora.protocol.RequestHeader; +import net.yacy.cora.util.ByteBuffer; import net.yacy.cora.util.ConcurrentLog; import net.yacy.data.UserDB.AccessRight; import net.yacy.data.UserDB.Entry; @@ -911,47 +912,43 @@ public class YaCyDefaultServlet extends HttpServlet { TemplateEngine.writeTemplate(fis, bas, templatePatterns, "-UNRESOLVED_PATTERN-".getBytes("UTF-8")); fis.close(); // handle SSI - doContentMod (bas.toByteArray(),request,response); + parseSSI (bas.toByteArray(),request,response); } } } - protected void doContentMod(final byte[] in, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - net.yacy.cora.util.ByteBuffer buffer = new net.yacy.cora.util.ByteBuffer(in); + /** + * parse SSI line and include resource () + */ + protected void parseSSI(final byte[] in, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + ByteBuffer buffer = new ByteBuffer(in); OutputStream out = response.getOutputStream(); - - // check and handle SSI (ServerSideIncludes) - int off = 0; - int p = buffer.indexOf("".getBytes(), p + 10); - - out.write(in, off, p - off); + final byte[] inctxt ="".getBytes(), p + 24)) > 0 ) { // min length 24; " + p = buffer.indexOf(inctxt, offset); } + out.write(in, offset, in.length - offset); } + /** * TODO: add same functionality & checks as in HTTPDemon.parseMultipart *