From 98c6675159a3245d913d3b67fd81b55e718ae876 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Fri, 21 Oct 2022 11:42:03 +1100 Subject: [PATCH] fix bugs in CachingHttpContentFactory, ResourceService and FileMappedHttpContentFactory Signed-off-by: Lachlan Roberts --- .../org/eclipse/jetty/http/CachingHttpContentFactory.java | 2 +- .../eclipse/jetty/http/FileMappedHttpContentFactory.java | 2 +- .../main/java/org/eclipse/jetty/server/ResourceService.java | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/CachingHttpContentFactory.java b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/CachingHttpContentFactory.java index c38930d4abd..644efdf1a12 100644 --- a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/CachingHttpContentFactory.java +++ b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/CachingHttpContentFactory.java @@ -217,7 +217,7 @@ public class CachingHttpContentFactory implements HttpContent.Factory if (wasAdded.get()) shrinkCache(); - return cachingHttpContent; + return (cachingHttpContent instanceof NotFoundHttpContent) ? null : cachingHttpContent; } return httpContent; } diff --git a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/FileMappedHttpContentFactory.java b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/FileMappedHttpContentFactory.java index 02612a55e15..f927df1da66 100644 --- a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/FileMappedHttpContentFactory.java +++ b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/FileMappedHttpContentFactory.java @@ -37,7 +37,7 @@ public class FileMappedHttpContentFactory implements HttpContent.Factory public HttpContent getContent(String path) throws IOException { HttpContent content = _factory.getContent(path); - if (content.getContentLengthValue() > 16 * 1024) + if (content != null && content.getContentLengthValue() > 16 * 1024) return new FileMappedContent(content); return content; } diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java index 51c8bdf3b93..4492532b850 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java @@ -868,10 +868,10 @@ public class ResourceService @Override protected Action process() throws Throwable { - // TODO: use BufferUtil if (!source.isOpen()) return Action.SUCCEEDED; - byteBuffer.clear(); + + BufferUtil.clearToFill(byteBuffer.getBuffer()); int read = source.read(byteBuffer.getBuffer()); if (read == -1) { @@ -879,7 +879,7 @@ public class ResourceService sink.write(true, BufferUtil.EMPTY_BUFFER, this); return Action.SCHEDULED; } - byteBuffer.getBuffer().flip(); + BufferUtil.flipToFlush(byteBuffer.getBuffer(), 0); sink.write(false, byteBuffer.getBuffer(), this); return Action.SCHEDULED; }