From 73ac87e70a9fd40506ab7abb407640d06f195315 Mon Sep 17 00:00:00 2001 From: t-burch Date: Wed, 8 Nov 2023 17:35:44 +0100 Subject: [PATCH] Only generated index if enabled, else 404 Signed-off-by: t-burch --- .../server/WebServerInterceptor.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java index 7cbe583496..4214827519 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java @@ -88,7 +88,6 @@ public Outcome handleRequest(Exchange exc) throws Exception { log.debug("request: " + uri); if (escapesPath(uri) || escapesPath(router.getUriFactory().create(uri).getPath())) { - exc.setResponse(Response.badRequest().body("").build()); return Outcome.ABORT; } @@ -96,7 +95,6 @@ public Outcome handleRequest(Exchange exc) throws Exception { if (uri.startsWith("/")) uri = uri.substring(1); - try { exc.setTimeReqSent(System.currentTimeMillis()); @@ -113,8 +111,7 @@ public Outcome handleRequest(Exchange exc) throws Exception { exc.setReceived(); exc.setTimeResReceived(System.currentTimeMillis()); return Outcome.RETURN; - } catch (ResourceRetrievalException e2) { - } + } catch (ResourceRetrievalException ignored) {} } String uri2 = uri + "/"; for (String i : index) { @@ -124,20 +121,22 @@ public Outcome handleRequest(Exchange exc) throws Exception { exc.setReceived(); exc.setTimeResReceived(System.currentTimeMillis()); return Outcome.RETURN; - } catch (ResourceRetrievalException e2) { - } + } catch (ResourceRetrievalException ignored) {} } } - Outcome outcome = generateHtmlResponseFromChildren(exc, uri); - if (outcome != null) { - return outcome; + if (generateIndex) { + Outcome outcome = generateHtmlResponseFromChildren(exc, uri); + if (outcome != null) { + return outcome; + } } exc.setResponse(Response.notFound().build()); return Outcome.ABORT; } + private Outcome generateHtmlResponseFromChildren(Exchange exc, String uri) throws FileNotFoundException { List children = router.getResolverMap().getChildren(ResolverMap.combine(router.getBaseLocation(), docBase, uri)); if (children == null) {