From b611dcc896327e5db93961c3d43b793c11f74987 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Fri, 15 Nov 2024 01:13:41 +0000 Subject: [PATCH] Remove unused functions and dependencies --- project.clj | 3 --- src/duct/handler/root.clj | 8 ------ src/duct/middleware/web.clj | 45 ------------------------------- src/duct/router/cascading.clj | 6 ----- test/duct/handler/root_test.clj | 13 --------- test/duct/middleware/web_test.clj | 32 ---------------------- 6 files changed, 107 deletions(-) delete mode 100644 src/duct/handler/root.clj delete mode 100644 src/duct/router/cascading.clj delete mode 100644 test/duct/handler/root_test.clj diff --git a/project.clj b/project.clj index 87f95da..ae9908d 100644 --- a/project.clj +++ b/project.clj @@ -7,10 +7,7 @@ [org.duct-framework/logger "0.4.0"] [org.duct-framework/server.http.jetty "0.3.0"] [org.duct-framework/router.reitit "0.2.0"] - [compojure "1.7.1"] [integrant "0.13.1"] - [metosin/jsonista "0.3.12"] - [metosin/muuntaja "0.6.10"] [org.slf4j/slf4j-nop "2.0.16"] [org.webjars/normalize.css "5.0.0"] [ring/ring-core "1.13.0"] diff --git a/src/duct/handler/root.clj b/src/duct/handler/root.clj deleted file mode 100644 index c13208e..0000000 --- a/src/duct/handler/root.clj +++ /dev/null @@ -1,8 +0,0 @@ -(ns duct.handler.root - (:require [integrant.core :as ig])) - -(defmethod ig/prep-key :duct.handler/root [_ config] - (merge {:router (ig/ref :duct/router)} config)) - -(defmethod ig/init-key :duct.handler/root [_ {:keys [middleware router]}] - ((apply comp (reverse middleware)) router)) diff --git a/src/duct/middleware/web.clj b/src/duct/middleware/web.clj index df1de89..7892b58 100644 --- a/src/duct/middleware/web.clj +++ b/src/duct/middleware/web.clj @@ -1,8 +1,6 @@ (ns duct.middleware.web (:require [duct.logger :as logger] [integrant.core :as ig] - [muuntaja.core :as mc] - [muuntaja.middleware :as mm] [ring.middleware.defaults :refer [wrap-defaults]] [ring.middleware.stacktrace :refer [wrap-stacktrace]] [ring.middleware.webjars :refer [wrap-webjars]] @@ -51,9 +49,6 @@ (defn- internal-error [response] (response/status response 500)) -(defn- not-found [response] - (response/status response 404)) - (defn wrap-hide-errors "Middleware that hides any uncaught exceptions behind a 500 'Internal Error' response generated by an error handler. Intended for use in production when @@ -69,32 +64,6 @@ (handler request respond (fn [_] (respond (internal-error (error-handler request))))) (catch Throwable _ (respond (internal-error (error-handler request)))))))) -(defn wrap-not-found - "Middleware that returns a 404 'Not Found' response from an error handler if - the base handler returns nil." - [handler error-handler] - (fn - ([request] - (or (handler request) (not-found (error-handler request)))) - ([request respond raise] - (handler request #(respond (or % (not-found (error-handler request)))) raise)))) - -(defn- route-aliases-request [request aliases] - (if-let [alias (aliases (:uri request))] - (assoc request :uri alias) - request)) - -(defn wrap-route-aliases - "Middleware that takes a map of URI aliases. If the URI of the request matches - a URI in the map's keys, the URI is changed to the value corresponding to that - key." - [handler aliases] - (fn - ([request] - (handler (route-aliases-request request aliases))) - ([request respond raise] - (handler (route-aliases-request request aliases) respond raise)))) - (defmethod ig/init-key ::log-requests [_ {:keys [logger options]}] #(wrap-log-requests % logger (dissoc options :logger))) @@ -105,12 +74,6 @@ (defmethod ig/init-key ::hide-errors [_ {:keys [error-handler]}] #(wrap-hide-errors % error-handler)) -(defmethod ig/init-key ::not-found [_ {:keys [error-handler]}] - #(wrap-not-found % error-handler)) - -(defmethod ig/init-key ::route-aliases [_ aliases] - #(wrap-route-aliases % aliases)) - (defmethod ig/init-key ::defaults [_ defaults] #(wrap-defaults % defaults)) @@ -119,11 +82,3 @@ (defmethod ig/init-key ::stacktrace [_ options] #(wrap-stacktrace % options)) - -(defn- deep-merge [a b] - (if (and (map? a) (map? b)) - (merge-with deep-merge a b) - b)) - -(defmethod ig/init-key ::format [_ options] - #(mm/wrap-format % (deep-merge mc/default-options options))) diff --git a/src/duct/router/cascading.clj b/src/duct/router/cascading.clj deleted file mode 100644 index 924a0a9..0000000 --- a/src/duct/router/cascading.clj +++ /dev/null @@ -1,6 +0,0 @@ -(ns duct.router.cascading - (:require [compojure.core :as compojure] - [integrant.core :as ig])) - -(defmethod ig/init-key :duct.router/cascading [_ routes] - (apply compojure/routes routes)) diff --git a/test/duct/handler/root_test.clj b/test/duct/handler/root_test.clj deleted file mode 100644 index 8fd2f95..0000000 --- a/test/duct/handler/root_test.clj +++ /dev/null @@ -1,13 +0,0 @@ -(ns duct.handler.root-test - (:require [clojure.test :refer :all] - [duct.handler.root :as root] - [integrant.core :as ig])) - -(deftest test-root-handler - (let [m {:duct.handler/root - {:router (fn [_] {:status 200, :headers {}, :body "foo"}) - :middleware [(fn [f] #(assoc-in (f %) [:headers "X-Foo"] "bar")) - (fn [f] #(assoc-in (f %) [:headers "X-Foo"] "baz"))]}} - f (:duct.handler/root (ig/init m))] - (is (= (f {:request-method :get, :uri "/"}) - {:status 200, :headers {"X-Foo" "baz"}, :body "foo"})))) diff --git a/test/duct/middleware/web_test.clj b/test/duct/middleware/web_test.clj index 3a83d7c..489ddbc 100644 --- a/test/duct/middleware/web_test.clj +++ b/test/duct/middleware/web_test.clj @@ -1,6 +1,5 @@ (ns duct.middleware.web-test (:require [clojure.test :refer :all] - [compojure.core :as compojure] [duct.logger :as logger] [duct.middleware.web :refer :all] [integrant.core :as ig] @@ -81,34 +80,3 @@ (handler (mock/request :get "/") respond raise) (is (not (realized? raise))) (is (= @respond response)))))) - -(deftest test-wrap-not-found - (let [err-handler (make-error-handler "Not Found") - response {:status 404, :headers {}, :body "Not Found"}] - (testing "synchronous" - (let [handler (wrap-not-found (constantly nil) err-handler)] - (is (= (handler (mock/request :get "/")) response)))) - - (testing "asynchronous" - (let [handler (wrap-not-found (fn [_ respond _] (respond nil)) err-handler) - respond (promise) - raise (promise)] - (handler (mock/request :get "/") respond raise) - (is (not (realized? raise))) - (is (= @respond response)))))) - -(deftest test-wrap-route-aliases - (let [response {:status 200 - :headers {"Content-Type" "text/html; charset=utf-8"} - :body "foo"} - handler (-> (compojure/GET "/index.html" [] "foo") - (wrap-route-aliases {"/" "/index.html"}))] - (testing "synchronous" - (is (= (handler (mock/request :get "/")) response))) - - (testing "asynchronous" - (let [respond (promise) - raise (promise)] - (handler (mock/request :get "/") respond raise) - (is (not (realized? raise))) - (is (= @respond response))))))