From 5282755f8e0530d126152af79715228f7d1aeaf7 Mon Sep 17 00:00:00 2001 From: zhongxiao Date: Tue, 23 Jun 2020 02:11:25 +0800 Subject: [PATCH] http-server example: Resolve access to subfolder --- examples/http_server.clj | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/http_server.clj b/examples/http_server.clj index a1db0a19..fecae0a0 100755 --- a/examples/http_server.clj +++ b/examples/http_server.clj @@ -34,7 +34,7 @@ (string/join (if attrs? (rest body) body)) (name tag)))) body (cond - (not (.exists f)) "" + (not (.exists f)) (str path " not exist") (.isFile f) (slurp f) (.isDirectory f) (format "\n%s" (html :html @@ -45,7 +45,10 @@ (html :tt (apply html :pre (for [i (.list f)] - (html :div (html :a {:href (format "\"%s\"" i)} i)))))))))] + (html :div + (html :a + {:href (str (if (> (count path) 1) path) "/" i)} i) + ))))))))] (prn path) (.write out (format "HTTP/1.1 %s OK\r\nContent-Length: %s\r\n\r\n%s" status