diff --git a/ring-core/src/ring/middleware/cookies.clj b/ring-core/src/ring/middleware/cookies.clj index 057ce0014..a6303e67a 100644 --- a/ring-core/src/ring/middleware/cookies.clj +++ b/ring-core/src/ring/middleware/cookies.clj @@ -123,7 +123,7 @@ (for [[key value] cookies] (if (map? value) (apply str (write-value key (:value value) encoder) - (write-attr-map (dissoc value :value))) + (write-attr-map (dissoc value :value))) (write-value key value encoder)))) (defn- set-cookies [response encoder] diff --git a/ring-core/src/ring/middleware/multipart_params/temp_file.clj b/ring-core/src/ring/middleware/multipart_params/temp_file.clj index e4e78747f..bb6b3791d 100644 --- a/ring-core/src/ring/middleware/multipart_params/temp_file.clj +++ b/ring-core/src/ring/middleware/multipart_params/temp_file.clj @@ -10,10 +10,10 @@ (defmacro ^{:private true} do-every [delay & body] `(background-thread - #(while true - (Thread/sleep ~(with-meta `(* ~delay 1000) {:tag 'long})) - (try ~@body - (catch Exception ex#))))) + #(while true + (Thread/sleep ~(with-meta `(* ~delay 1000) {:tag 'long})) + (try ~@body + (catch Exception ex#))))) (defn- expired? [^File file expiry-time] (< (.lastModified file) @@ -34,14 +34,14 @@ (defn- start-clean-up [file-set expires-in] (when expires-in (do-every expires-in - (remove-old-files file-set expires-in)))) + (remove-old-files file-set expires-in)))) (defn- ensure-shutdown-clean-up [file-set] (.addShutdownHook - (Runtime/getRuntime) - (Thread. - #(doseq [^File file @file-set] - (.delete file))))) + (Runtime/getRuntime) + (Thread. + #(doseq [^File file @file-set] + (.delete file))))) (defn temp-file-store "Returns a function that stores multipart file parameters as temporary files. @@ -60,13 +60,13 @@ {:arglists '([] [options])} ([] (temp-file-store {:expires-in 3600})) ([{:keys [expires-in]}] - (let [file-set (atom #{}) - clean-up (delay (start-clean-up file-set expires-in))] - (ensure-shutdown-clean-up file-set) - (fn [item] - (force clean-up) - (let [temp-file (make-temp-file file-set)] - (io/copy (:stream item) temp-file) - (-> (select-keys item [:filename :content-type]) - (assoc :tempfile temp-file - :size (.length temp-file)))))))) + (let [file-set (atom #{}) + clean-up (delay (start-clean-up file-set expires-in))] + (ensure-shutdown-clean-up file-set) + (fn [item] + (force clean-up) + (let [temp-file (make-temp-file file-set)] + (io/copy (:stream item) temp-file) + (-> (select-keys item [:filename :content-type]) + (assoc :tempfile temp-file + :size (.length temp-file)))))))) diff --git a/ring-core/src/ring/middleware/nested_params.clj b/ring-core/src/ring/middleware/nested_params.clj index ddfd97c7a..7b176d926 100644 --- a/ring-core/src/ring/middleware/nested_params.clj +++ b/ring-core/src/ring/middleware/nested_params.clj @@ -38,11 +38,11 @@ "Return a list of name-value pairs for a parameter map." [params] (mapcat - (fn [[name value]] - (if (and (sequential? value) (not (coll? (first value)))) - (for [v value] [name v]) - [[name value]])) - params)) + (fn [[name value]] + (if (and (sequential? value) (not (coll? (first value)))) + (for [v value] [name v]) + [[name value]])) + params)) (defn- nest-params "Takes a flat map of parameters and turns it into a nested map of @@ -50,10 +50,10 @@ into keys." [params parse] (reduce - (fn [m [k v]] - (assoc-nested m (parse k) v)) - {} - (param-pairs params))) + (fn [m [k v]] + (assoc-nested m (parse k) v)) + {} + (param-pairs params))) (defn nested-params-request "Converts a request with a flat map of parameters to a nested map. diff --git a/ring-core/src/ring/middleware/session.clj b/ring-core/src/ring/middleware/session.clj index 57f809985..12d30b0ab 100644 --- a/ring-core/src/ring/middleware/session.clj +++ b/ring-core/src/ring/middleware/session.clj @@ -44,7 +44,7 @@ (defn- bare-session-response [response {session-key :session/key} {:keys [store cookie-name cookie-attrs]}] (let [new-session-key (if (contains? response :session) - (if-let [session (response :session)] + (if-let [session (response :session)] (if (:recreate (meta session)) (do (store/delete-session store session-key) @@ -103,17 +103,17 @@ :set-cookies? - If true, automatically include cookie middleware. Defaults to true for backward compatibility." ([handler] - (wrap-session handler {})) + (wrap-session handler {})) ([handler options] - (let [options (session-options options)] - (fn - ([request] - (let [request (session-request request options)] - (-> (handler request) - (session-response request options)))) - ([request respond raise] - (let [request (session-request request options)] - (handler request - (fn [response] - (respond (session-response response request options))) - raise))))))) + (let [options (session-options options)] + (fn + ([request] + (let [request (session-request request options)] + (-> (handler request) + (session-response request options)))) + ([request respond raise] + (let [request (session-request request options)] + (handler request + (fn [response] + (respond (session-response response request options))) + raise))))))) diff --git a/ring-core/src/ring/middleware/session/cookie.clj b/ring-core/src/ring/middleware/session/cookie.clj index b277015b5..2917acd4a 100644 --- a/ring-core/src/ring/middleware/session/cookie.clj +++ b/ring-core/src/ring/middleware/session/cookie.clj @@ -42,8 +42,8 @@ iv (random/bytes (.getBlockSize cipher))] (.init cipher Cipher/ENCRYPT_MODE secret-key (IvParameterSpec. iv)) (->> (.doFinal cipher data) - (concat iv) - (byte-array)))) + (concat iv) + (byte-array)))) (defn- decrypt "Decrypt an array of bytes with a key." @@ -121,6 +121,6 @@ clojure.core/print-method or clojure.core/print-dup multimethods." ([] (cookie-store {})) ([options] - (let [key (get-secret-key options)] - (assert (valid-secret-key? key) "the secret key must be exactly 16 bytes") - (CookieStore. key options)))) + (let [key (get-secret-key options)] + (assert (valid-secret-key? key) "the secret key must be exactly 16 bytes") + (CookieStore. key options)))) diff --git a/ring-core/src/ring/util/io.clj b/ring-core/src/ring/util/io.clj index ffcf92e95..0584ea081 100644 --- a/ring-core/src/ring/util/io.clj +++ b/ring-core/src/ring/util/io.clj @@ -2,11 +2,11 @@ "Utility functions for handling I/O." (:require [clojure.java.io :as io]) (:import [java.io PipedInputStream - PipedOutputStream - ByteArrayInputStream - File - Closeable - IOException])) + PipedOutputStream + ByteArrayInputStream + File + Closeable + IOException])) (defn piped-input-stream "Create an input stream from a function that takes an output stream as its @@ -33,9 +33,9 @@ "Returns a ByteArrayInputStream for the given String." {:added "1.1"} ([^String s] - (ByteArrayInputStream. (.getBytes s))) + (ByteArrayInputStream. (.getBytes s))) ([^String s ^String encoding] - (ByteArrayInputStream. (.getBytes s encoding)))) + (ByteArrayInputStream. (.getBytes s encoding)))) (defn close! "Ensure a stream is closed, swallowing any exceptions." diff --git a/ring-core/src/ring/util/mime_type.clj b/ring-core/src/ring/util/mime_type.clj index 0da9f60be..acf4c2f07 100644 --- a/ring-core/src/ring/util/mime_type.clj +++ b/ring-core/src/ring/util/mime_type.clj @@ -111,7 +111,7 @@ "Get the mimetype from the filename extension. Takes an optional map of extensions to mimetypes that overrides values in the default-mime-types map." ([filename] - (ext-mime-type filename {})) + (ext-mime-type filename {})) ([filename mime-types] - (let [mime-types (merge default-mime-types mime-types)] - (mime-types (filename-ext filename))))) + (let [mime-types (merge default-mime-types mime-types)] + (mime-types (filename-ext filename))))) diff --git a/ring-core/src/ring/util/request.clj b/ring-core/src/ring/util/request.clj index be11c7800..8c00be5d9 100644 --- a/ring-core/src/ring/util/request.clj +++ b/ring-core/src/ring/util/request.clj @@ -81,5 +81,5 @@ [request ^String context] {:pre [(in-context? request context)]} (assoc request - :context context - :path-info (subs (:uri request) (.length context)))) + :context context + :path-info (subs (:uri request) (.length context)))) diff --git a/ring-core/src/ring/util/response.clj b/ring-core/src/ring/util/response.clj index a638f7a27..35c96e183 100644 --- a/ring-core/src/ring/util/response.clj +++ b/ring-core/src/ring/util/response.clj @@ -40,9 +40,9 @@ {:added "1.2"} ([url] (created url nil)) ([url body] - {:status 201 - :headers {"Location" url} - :body body})) + {:status 201 + :headers {"Location" url} + :body body})) (defn bad-request "Returns a 400 'bad request' response." @@ -126,9 +126,9 @@ (if-let [^File file (safely-find-file path opts)] (cond (.isDirectory file) - (and (:index-files? opts true) (find-index-file file)) + (and (:index-files? opts true) (find-index-file file)) (.exists file) - file))) + file))) (defn- file-data [^File file] {:content file @@ -214,10 +214,10 @@ {:added "1.1"} [resp charset] (update-header resp "Content-Type" - (fn [content-type] - (-> (or content-type "text/plain") - (str/replace #";\s*charset=[^;]*" "") - (str "; charset=" charset))))) + (fn [content-type] + (-> (or content-type "text/plain") + (str/replace #";\s*charset=[^;]*" "") + (str "; charset=" charset))))) (defn get-charset "Gets the character encoding of a Ring response." diff --git a/ring-core/test/ring/middleware/test/content_type.clj b/ring-core/test/ring/middleware/test/content_type.clj index 46e78d867..402d3632a 100644 --- a/ring-core/test/ring/middleware/test/content_type.clj +++ b/ring-core/test/ring/middleware/test/content_type.clj @@ -69,6 +69,6 @@ (deftest content-type-response-test (testing "function exists" (is (fn? content-type-response))) - + (testing "nil response" (is (nil? (content-type-response nil {}))))) diff --git a/ring-core/test/ring/middleware/test/cookies.clj b/ring-core/test/ring/middleware/test/cookies.clj index bb1a75794..44c17a28c 100644 --- a/ring-core/test/ring/middleware/test/cookies.clj +++ b/ring-core/test/ring/middleware/test/cookies.clj @@ -51,7 +51,7 @@ (update-in headers ["Set-Cookie"] split-header))) (deftest wrap-cookies-set-extra-attrs - (let [cookies {"a" {:value "b", :path "/", :secure true, :http-only true }} + (let [cookies {"a" {:value "b", :path "/", :secure true, :http-only true}} handler (constantly {:cookies cookies}) resp ((wrap-cookies handler) {})] (is (= {"Set-Cookie" #{"a=b" "Path=/" "Secure" "HttpOnly"}} @@ -230,7 +230,7 @@ resp ((wrap-cookies handler) {}) expires "Thu, 31 Dec 2015 00:00:00 GMT"] (is (= {"Set-Cookie" #{"a=b" "Path=/" "Secure" "HttpOnly" (str "Expires=" expires)}} - (split-set-cookie (:headers resp))))) + (split-set-cookie (:headers resp))))) (finally (java.util.Locale/setDefault default-locale))))) diff --git a/ring-core/test/ring/middleware/test/file_info.clj b/ring-core/test/ring/middleware/test/file_info.clj index 4a9bceaeb..498d183aa 100644 --- a/ring-core/test/ring/middleware/test/file_info.clj +++ b/ring-core/test/ring/middleware/test/file_info.clj @@ -11,19 +11,19 @@ (def unknown-file (File. "test/ring/assets/random.xyz")) (def unknown-file-app (wrap-file-info (constantly {:headers {} :body unknown-file}))) -(defmacro with-last-modified +(defmacro with-last-modified "Lets us use a known file modification time for tests, without permanently changing the file's modification time." [[file new-time] form] - `(let [old-time# (.lastModified ~file)] + `(let [old-time# (.lastModified ~file)] (.setLastModified ~file ~(* new-time 1000)) (try ~form (finally (.setLastModified ~file old-time#))))) (def custom-type-app (wrap-file-info - (constantly {:headers {} :body known-file}) - {"txt" "custom/type"})) + (constantly {:headers {} :body known-file}) + {"txt" "custom/type"})) (deftest wrap-file-info-non-file-response (is (= {:headers {} :body "body"} (non-file-app {})))) @@ -60,7 +60,7 @@ "Last-Modified" "Thu, 14 Jan 2010 22:00:00 +0000"} :body ""} (known-file-app - {:headers {"if-modified-since" "Thu, 14 Jan 2010 22:00:00 +0000" }}))))) + {:headers {"if-modified-since" "Thu, 14 Jan 2010 22:00:00 +0000"}}))))) (deftest wrap-file-info-if-modified-miss (with-last-modified [known-file 1263506400] @@ -69,7 +69,7 @@ "Last-Modified" "Thu, 14 Jan 2010 22:00:00 +0000"} :body known-file} (known-file-app - {:headers {"if-modified-since" "Wed, 13 Jan 2010 22:00:00 +0000"}}))))) + {:headers {"if-modified-since" "Wed, 13 Jan 2010 22:00:00 +0000"}}))))) (deftest wrap-file-info-cps-test (testing "file response" @@ -85,7 +85,7 @@ :body known-file} @response)) (is (not (realized? exception)))))) - + (testing "non-file response" (let [handler (wrap-file-info (fn [_ respond _] (respond {:headers {} :body "body"}))) diff --git a/ring-core/test/ring/middleware/test/flash.clj b/ring-core/test/ring/middleware/test/flash.clj index c7591868a..c24689bdc 100644 --- a/ring-core/test/ring/middleware/test/flash.clj +++ b/ring-core/test/ring/middleware/test/flash.clj @@ -11,9 +11,9 @@ (deftest flash-is-retrieved-from-session (let [message {:error "Could not save"} handler (wrap-flash - (fn [request] - (is (= (:flash request) message)) - {}))] + (fn [request] + (is (= (:flash request) message)) + {}))] (handler {:session {:_flash message}}))) (deftest flash-is-removed-after-read diff --git a/ring-core/test/ring/middleware/test/multipart_params.clj b/ring-core/test/ring/middleware/test/multipart_params.clj index 577e35fa0..2fb0fd239 100644 --- a/ring-core/test/ring/middleware/test/multipart_params.clj +++ b/ring-core/test/ring/middleware/test/multipart_params.clj @@ -88,9 +88,9 @@ :body (string-input-stream form-body "UTF-8")} response (promise) exception (promise)] - (handler request response exception) - (is (= (get-in @response [:multipart-params "foo"]) "bar")) - (is (not (realized? exception))))) + (handler request response exception) + (is (= (get-in @response [:multipart-params "foo"]) "bar")) + (is (not (realized? exception))))) (deftest multipart-params-request-test (is (fn? multipart-params-request))) @@ -105,7 +105,7 @@ (str "multipart/form-data; boundary=XXXX")} :body (string-input-stream form-body "UTF-8")} request* (multipart-params-request request)] - (is (= (get-in request* [:multipart-params "foo"]) "Øæß箣èé")))) + (is (= (get-in request* [:multipart-params "foo"]) "Øæß箣èé")))) (deftest parts-may-have-invidual-charsets-in-content-type (let [form-body (str "--XXXX\r\n" diff --git a/ring-core/test/ring/middleware/test/resource.clj b/ring-core/test/ring/middleware/test/resource.clj index 1cae8f216..231ff42c9 100644 --- a/ring-core/test/ring/middleware/test/resource.clj +++ b/ring-core/test/ring/middleware/test/resource.clj @@ -33,7 +33,7 @@ no-loader (wrap-resource test-handler "/ring/assets") with-loader (wrap-resource test-handler "/ring/assets" {:loader loader})] (are [request body] (= (slurp (:body (no-loader request))) body) - {:request-method :get, :uri "/foo.html"} "foo") + {:request-method :get, :uri "/foo.html"} "foo") (are [request body] (= (slurp (:body (with-loader request))) body) {:request-method :get, :uri "/foo.html"} "foo-in-jar") (testing "does accept trailing slash in asset path" diff --git a/ring-core/test/ring/middleware/test/session.clj b/ring-core/test/ring/middleware/test/session.clj index 033fe1564..b673774e7 100644 --- a/ring-core/test/ring/middleware/test/session.clj +++ b/ring-core/test/ring/middleware/test/session.clj @@ -101,10 +101,10 @@ (let [store (make-store (constantly {}) (constantly "foo:bar") (constantly nil)) - handler (constantly {:session {:foo "bar"}}) - handler (wrap-session handler {:store store + handler (constantly {:session {:foo "bar"}}) + handler (wrap-session handler {:store store :cookie-attrs {:max-age 5 :path "/foo"}}) - response (handler {:cookies {}}) + response (handler {:cookies {}}) session-cookie (get-session-cookie response)] (is (and (.contains session-cookie "ring-session=foo%3Abar") (.contains session-cookie "Max-Age=5") @@ -115,10 +115,10 @@ (let [store (make-store (constantly {}) (constantly "foo:bar") (constantly nil)) - handler (constantly {:session {:foo "bar"} - :cookies {"cookie2" "value2"}}) - handler (wrap-session handler {:store store :cookie-attrs {:max-age 5}}) - response (handler {:cookies {}})] + handler (constantly {:session {:foo "bar"} + :cookies {"cookie2" "value2"}}) + handler (wrap-session handler {:store store :cookie-attrs {:max-age 5}}) + response (handler {:cookies {}})] (is (= (first (remove is-session-cookie? (get-cookies response))) "cookie2=value2")))) @@ -126,9 +126,9 @@ (let [store (make-store (constantly {}) (constantly "foo:bar") (constantly nil)) - handler (constantly {:session {:foo "bar"}}) - handler (wrap-session handler {:store store, :root "/foo"}) - response (handler {:cookies {}})] + handler (constantly {:session {:foo "bar"}}) + handler (wrap-session handler {:store store, :root "/foo"}) + response (handler {:cookies {}})] (is (.contains (get-session-cookie response) "Path=/foo")))) @@ -136,10 +136,10 @@ (let [store (make-store (constantly {}) (constantly "foo:bar") (constantly nil)) - handler (constantly {:session {:foo "bar"} + handler (constantly {:session {:foo "bar"} :session-cookie-attrs {:max-age 5}}) - handler (wrap-session handler {:store store}) - response (handler {:cookies {}})] + handler (wrap-session handler {:store store}) + response (handler {:cookies {}})] (is (.contains (get-session-cookie response) "Max-Age=5")))) @@ -147,9 +147,9 @@ (let [store (make-store (constantly {}) (constantly {}) (constantly nil)) - handler (constantly {:session {}}) - handler (wrap-session handler {:store store :cookie-attrs {:http-only false}}) - response (handler {:cookies {}})] + handler (constantly {:session {}}) + handler (wrap-session handler {:store store :cookie-attrs {:http-only false}}) + response (handler {:cookies {}})] (is (not (.contains (get-session-cookie response) "HttpOnly"))))) diff --git a/ring-core/test/ring/test/websocket.clj b/ring-core/test/ring/test/websocket.clj index b36571fc8..da695f005 100644 --- a/ring-core/test/ring/test/websocket.clj +++ b/ring-core/test/ring/test/websocket.clj @@ -3,7 +3,6 @@ [ring.websocket :as ws] [ring.websocket.protocols :as wsp])) - (deftest test-upgrade-request? (is (not (ws/upgrade-request? {}))) (is (ws/upgrade-request? {:headers {"connection" "Upgrade" diff --git a/ring-core/test/ring/util/test/response.clj b/ring-core/test/ring/util/test/response.clj index 3016ba100..de6994549 100644 --- a/ring-core/test/ring/util/test/response.clj +++ b/ring-core/test/ring/util/test/response.clj @@ -12,12 +12,12 @@ (redirect "/foo") :status) y) - :moved-permanently 301 - :found 302 - :see-other 303 - :temporary-redirect 307 - :permanent-redirect 308 - 300 300)) + :moved-permanently 301 + :found 302 + :see-other 303 + :temporary-redirect 307 + :permanent-redirect 308 + 300 300)) (deftest test-redirect-after-post (is (= {:status 303 :headers {"Location" "http://example.com"} :body ""} @@ -103,10 +103,10 @@ new-loader# (java.net.URLClassLoader. (into-array [(.toURL ~dir)]) original-loader#)] (try - (.setContextClassLoader current-thread# new-loader#) - ~@forms - (finally - (.setContextClassLoader current-thread# original-loader#))))) + (.setContextClassLoader current-thread# new-loader#) + ~@forms + (finally + (.setContextClassLoader current-thread# original-loader#))))) (defn- make-jar-url [jar-path res-path] (io/as-url (str "jar:file:" jar-path "!/" res-path))) diff --git a/ring-devel/src/ring/handler/dump.clj b/ring-devel/src/ring/handler/dump.clj index c067ded6f..9e617260f 100644 --- a/ring-devel/src/ring/handler/dump.clj +++ b/ring-devel/src/ring/handler/dump.clj @@ -12,39 +12,39 @@ (def ^:no-doc ring-keys '(:server-port :server-name :remote-addr :uri :query-string :scheme - :request-method :content-type :content-length :character-encoding - :ssl-client-cert :headers :body)) + :request-method :content-type :content-length :character-encoding + :ssl-client-cert :headers :body)) (defn- style-resource [path] (html [:style {:type "text/css"} (slurp (io/resource path))])) (defn- req-pair [key req] (html - [:tr - [:td.key (h (str key))] - [:td.val (h (pr-str (key req)))]])) + [:tr + [:td.key (h (str key))] + [:td.val (h (pr-str (key req)))]])) (defhtml ^:no-doc template [req] (doctype :xhtml-transitional) [:html {:xmlns "http://www.w3.org/1999/xhtml"} - [:head - [:title "Ring: Request Dump"] - (style-resource "ring/css/dump.css")] - [:body - [:div#content - [:h3.info "Ring Request Values"] - [:table.request - [:tbody - (for [key ring-keys] - (req-pair key req))]] - (if-let [user-keys (set/difference (set (keys req)) (set ring-keys))] - (html - [:br] - [:table.request.user - [:tbody [:tr - (for [key (sort user-keys)] - (req-pair key req))]]]))]]]) + [:head + [:title "Ring: Request Dump"] + (style-resource "ring/css/dump.css")] + [:body + [:div#content + [:h3.info "Ring Request Values"] + [:table.request + [:tbody + (for [key ring-keys] + (req-pair key req))]] + (if-let [user-keys (set/difference (set (keys req)) (set ring-keys))] + (html + [:br] + [:table.request.user + [:tbody [:tr + (for [key (sort user-keys)] + (req-pair key req))]]]))]]]) (defn handle-dump "Returns a HTML response that shows the information in the request map. diff --git a/ring-devel/src/ring/middleware/lint.clj b/ring-devel/src/ring/middleware/lint.clj index 0549356ae..3d20c90d0 100644 --- a/ring-devel/src/ring/middleware/lint.clj +++ b/ring-devel/src/ring/middleware/lint.clj @@ -17,8 +17,8 @@ (catch Exception e (if-not (re-find #"^Ring lint error: " (.getMessage e)) (throw (Exception. (format - "Ring lint error: exception occurred when checking that %s on %s: %s" - message (pr-str val) (.getMessage e)))) + "Ring lint error: exception occurred when checking that %s on %s: %s" + message (pr-str val) (.getMessage e)))) (throw e))))) (defn- check-req @@ -27,66 +27,66 @@ (lint req map? "Ring request must a Clojure map") (lint (:server-port req) integer? - ":server-port must be an Integer") + ":server-port must be an Integer") (lint (:server-name req) string? - ":server-name must be a String") + ":server-name must be a String") (lint (:remote-addr req) string? - ":remote-addr must be a String") + ":remote-addr must be a String") (lint (:uri req) #(and (string? %) (.startsWith ^String % "/")) - ":uri must be a String starting with \"/\"") + ":uri must be a String starting with \"/\"") (lint (:query-string req) #(or (nil? %) (string? %)) - ":query-string must be nil or a String") + ":query-string must be nil or a String") (lint (:scheme req) #{:http :https} - ":scheme must be one of :http or :https") + ":scheme must be one of :http or :https") (lint (:request-method req) #(and (keyword? %) (= (name %) (str/lower-case (name %)))) - ":request-method must be a lowercase keyword") + ":request-method must be a lowercase keyword") (lint (:content-type req) #(or (nil? %) (string? %)) - ":content-type must be nil or a String") + ":content-type must be nil or a String") (lint (:content-length req) #(or (nil? %) (integer? %)) - ":content-length must be nil or an Integer") + ":content-length must be nil or an Integer") (lint (:character-encoding req) #(or (nil? %) (string? %)) - ":character-encoding must be nil or a String") + ":character-encoding must be nil or a String") (lint (:ssl-client-cert req) #(or (nil? %) (instance? X509Certificate %)) - ":ssl-client-cert must be nil or an X509Certificate") + ":ssl-client-cert must be nil or an X509Certificate") (let [headers (:headers req)] (lint headers map? - ":headers must be a Clojure map") + ":headers must be a Clojure map") (doseq [[hname hval] headers] (lint hname string? - "header names must be Strings") + "header names must be Strings") (lint hname #(= % (.toLowerCase ^String %)) - "header names must be in lower case") + "header names must be in lower case") (lint hval string? - "header values must be strings"))) + "header values must be strings"))) (lint (:body req) #(or (nil? %) (instance? InputStream %)) - ":body must be nil or an InputStream")) + ":body must be nil or an InputStream")) (defn- check-resp "Validates the response, throwing an exception on violations of the spec" [resp] (lint resp map? - "Ring response must be a Clojure map") + "Ring response must be a Clojure map") (lint (:status resp) #(and (integer? %) (>= % 100)) - ":status must be an Integer greater than or equal to 100") + ":status must be an Integer greater than or equal to 100") (let [headers (:headers resp)] (lint headers map? - ":headers must be a Clojure map") + ":headers must be a Clojure map") (doseq [[hname hval] headers] (lint hname string? - "header names must Strings") + "header names must Strings") (lint hval #(or (string? %) (every? string? %)) - "header values must be Strings or collections of Strings"))) + "header values must be Strings or collections of Strings"))) (lint (:body resp) #(or (nil? %) (string? %) (seq? %) (instance? File %) (instance? InputStream %)) - ":body must a String, ISeq, File, or InputStream")) + ":body must a String, ISeq, File, or InputStream")) (defn wrap-lint "Wrap a handler to validate incoming requests and outgoing responses diff --git a/ring-devel/test/ring/middleware/test/lint.clj b/ring-devel/test/ring/middleware/test/lint.clj index 1ee1785a7..c72c39d5d 100644 --- a/ring-devel/test/ring/middleware/test/lint.clj +++ b/ring-devel/test/ring/middleware/test/lint.clj @@ -40,12 +40,12 @@ (doseq [good# ~goods] (is (= valid-response (valid-response-app (assoc valid-request ~key good#))) - (format "%s is a valid value for request key %s" - (pr-str good#) ~key)))) + (format "%s is a valid value for request key %s" + (pr-str good#) ~key)))) (deftest ~bad-name (doseq [bad# ~bads] (is-lint-error - (fn [] (valid-response-app (assoc valid-request ~key bad#))))))))) + (fn [] (valid-response-app (assoc valid-request ~key bad#))))))))) (defmacro lints-resp [key goods bads] @@ -57,8 +57,8 @@ (let [response# (assoc valid-response ~key good#) app# (constant-app response#)] (is (= response# (app# valid-request)) - (format "%s is a valid value for response key %s" - (pr-str good#) ~key))))) + (format "%s is a valid value for response key %s" + (pr-str good#) ~key))))) (deftest ~bad-name (doseq [bad# ~bads] (let [response# (assoc valid-response ~key bad#) @@ -66,69 +66,68 @@ (is-lint-error (fn [] (app# valid-request))))))))) (lints-req :server-port - [80 8080] - [nil "80"]) + [80 8080] + [nil "80"]) (lints-req :server-name - ["localhost" "www.amazon.com" "192.0.2.235"] - [nil 123]) + ["localhost" "www.amazon.com" "192.0.2.235"] + [nil 123]) (lints-req :remote-addr - ["192.0.2.235" "0:0:0:0:0:0:0:1%0"] - [nil 123]) + ["192.0.2.235" "0:0:0:0:0:0:0:1%0"] + [nil 123]) (lints-req :uri - ["/" "/foo" "/foo/bar"] - [nil ""]) + ["/" "/foo" "/foo/bar"] + [nil ""]) (lints-req :query-string - [nil "" "foo=bar" "foo=bar&biz=bat"] - [:foo]) + [nil "" "foo=bar" "foo=bar&biz=bat"] + [:foo]) (lints-req :scheme - [:http :https] - [nil "http"]) + [:http :https] + [nil "http"]) (lints-req :request-method - [:get :head :options :put :patch :post :delete] - [nil :FOOBAR "get" 'get]) + [:get :head :options :put :patch :post :delete] + [nil :FOOBAR "get" 'get]) (lints-req :content-type - [nil "text/html"] - [:text/html]) + [nil "text/html"] + [:text/html]) (lints-req :content-length - [nil 123] - ["123"]) + [nil 123] + ["123"]) (lints-req :character-encoding - [nil "UTF-8"] - [:utf-8]) + [nil "UTF-8"] + [:utf-8]) (lints-req :ssl-client-cert - [nil (proxy [java.security.cert.X509Certificate] [] (toString [] "X509Certificate"))] - ["01234567890ABCDEF"]) + [nil (proxy [java.security.cert.X509Certificate] [] (toString [] "X509Certificate"))] + ["01234567890ABCDEF"]) (lints-req :headers - [{"foo" "bar"} {"bat" "Biz"} {"whiz-bang" "high-low"}] - [nil {:foo "bar"} {"bar" :foo} {"Bar" "foo"}]) + [{"foo" "bar"} {"bat" "Biz"} {"whiz-bang" "high-low"}] + [nil {:foo "bar"} {"bar" :foo} {"Bar" "foo"}]) (lints-req :body - [nil (string-input-stream "thebody")] - ["thebody" :thebody]) - + [nil (string-input-stream "thebody")] + ["thebody" :thebody]) (lints-resp :status - [100 301 500] - [nil "100" 99]) + [100 301 500] + [nil "100" 99]) (lints-resp :headers - [{} {"foo" "bar"} {"Biz" "Bat"} {"vert" ["high" "low"]} {"horz" #{"left right"}}] - [nil {:foo "bar"} {"foo" :bar} {"dir" 123}]) + [{} {"foo" "bar"} {"Biz" "Bat"} {"vert" ["high" "low"]} {"horz" #{"left right"}}] + [nil {:foo "bar"} {"foo" :bar} {"dir" 123}]) (lints-resp :body - [nil "thebody" (list "foo" "bar") (string-input-stream "thebody") (File. "test/ring/assets/foo.html")] - [123 :thebody]) + [nil "thebody" (list "foo" "bar") (string-input-stream "thebody") (File. "test/ring/assets/foo.html")] + [123 :thebody]) (deftest wrap-lint-cps-test (testing "valid request and response" diff --git a/ring-devel/test/ring/middleware/test/stacktrace.clj b/ring-devel/test/ring/middleware/test/stacktrace.clj index 88d5a34de..53c7c1a0d 100644 --- a/ring-devel/test/ring/middleware/test/stacktrace.clj +++ b/ring-devel/test/ring/middleware/test/stacktrace.clj @@ -5,7 +5,6 @@ (def exception-app (wrap-stacktrace (fn [_] (throw (Exception. "fail"))))) (def assert-app (wrap-stacktrace (fn [_] (assert (= 1 2))))) - (def html-req {:headers {"accept" "text/html"}}) (def js-req {:headers {"accept" "application/javascript"}}) (def plain-req {}) diff --git a/ring-jakarta-servlet/test/ring/util/jakarta/test/servlet.clj b/ring-jakarta-servlet/test/ring/util/jakarta/test/servlet.clj index 8956f08cf..6a6823f0c 100644 --- a/ring-jakarta-servlet/test/ring/util/jakarta/test/servlet.clj +++ b/ring-jakarta-servlet/test/ring/util/jakarta/test/servlet.clj @@ -110,27 +110,27 @@ :servlet-context-path "/foo" :ssl-client-cert cert :body body} - response (atom {})] + response (atom {})] (letfn [(handler [r] - (are [k v] (= (r k) v) - :server-port 8080 - :server-name "foobar" - :remote-addr "127.0.0.1" - :uri "/foo" - :query-string "a=b" - :scheme :http - :request-method :get - :protocol "HTTP/1.1" - :headers {"x-client" "Foo,Bar" - "x-server" "Baz" - "x-capital-i" "Qux"} - :content-type "text/plain" - :content-length 10 - :character-encoding "UTF-8" - :servlet-context-path "/foo" - :ssl-client-cert cert - :body body) - {:status 200, :headers {}})] + (are [k v] (= (r k) v) + :server-port 8080 + :server-name "foobar" + :remote-addr "127.0.0.1" + :uri "/foo" + :query-string "a=b" + :scheme :http + :request-method :get + :protocol "HTTP/1.1" + :headers {"x-client" "Foo,Bar" + "x-server" "Baz" + "x-capital-i" "Qux"} + :content-type "text/plain" + :content-length 10 + :character-encoding "UTF-8" + :servlet-context-path "/foo" + :ssl-client-cert cert + :body body) + {:status 200, :headers {}})] (testing "request" (run-servlet handler request response)) (testing "mapping request header names to lower case" @@ -138,10 +138,10 @@ (run-servlet handler request response)))) (testing "response" (letfn [(handler [r] - {:status 200 - :headers {"Content-Type" "text/plain" - "X-Server" "Bar"} - :body "Hello World"})] + {:status 200 + :headers {"Content-Type" "text/plain" + "X-Server" "Bar"} + :body "Hello World"})] (run-servlet handler request response) (is (= (@response :status) 200)) (is (= (@response :content-type) "text/plain")) @@ -191,7 +191,7 @@ (servlet-request request) (servlet-response response)) (is (= (@response :status) 200)) - (is (= (get-in @response [:headers "Content-Type" ]) "text/plain")) + (is (= (get-in @response [:headers "Content-Type"]) "text/plain")) (is (= (.toString (@response :body)) "Hello World")))) (defn- service-handler [_] diff --git a/ring-jetty-adapter/src/ring/adapter/jetty.clj b/ring-jetty-adapter/src/ring/adapter/jetty.clj index 2a16d7867..07dcf6adc 100644 --- a/ring-jetty-adapter/src/ring/adapter/jetty.clj +++ b/ring-jetty-adapter/src/ring/adapter/jetty.clj @@ -161,11 +161,11 @@ (defn- server-connector ^ServerConnector [^Server server & factories] (ServerConnector. server #^"[Lorg.eclipse.jetty.server.ConnectionFactory;" - (into-array ConnectionFactory factories))) + (into-array ConnectionFactory factories))) (defn- unix-domain-server-connector ^UnixDomainServerConnector [^Server server & factories] (UnixDomainServerConnector. server #^"[Lorg.eclipse.jetty.server.ConnectionFactory;" - (into-array ConnectionFactory factories))) + (into-array ConnectionFactory factories))) (defn- http-config ^HttpConfiguration [options] (doto (HttpConfiguration.) @@ -215,7 +215,6 @@ (.addExcludeProtocols context-server protocols)))) context-server)) - (defn- ssl-connector ^ServerConnector [^Server server options] (let [ssl-port (options :ssl-port 443) customizer (doto (SecureRequestCustomizer.) diff --git a/ring-jetty-adapter/test/ring/adapter/test/jetty.clj b/ring-jetty-adapter/test/ring/adapter/test/jetty.clj index e0a756735..526229267 100644 --- a/ring-jetty-adapter/test/ring/adapter/test/jetty.clj +++ b/ring-jetty-adapter/test/ring/adapter/test/jetty.clj @@ -20,7 +20,7 @@ [java.net ServerSocket ConnectException] [java.security KeyStore] [java.io SequenceInputStream ByteArrayInputStream InputStream - IOException] + IOException] [org.apache.http MalformedChunkCodingException])) (defn- hello-world [_request] @@ -451,12 +451,12 @@ {:status 200 :headers {"Transfer-Encoding" "chunked"} :body (SequenceInputStream. - (ByteArrayInputStream. (.getBytes (str (range 100000)) "UTF-8")) - (proxy [InputStream] [] - (read - ([] (throw (IOException. "test error"))) - ([^bytes _] (throw (IOException. "test error"))) - ([^bytes _ _ _] (throw (IOException. "test error"))))))}) + (ByteArrayInputStream. (.getBytes (str (range 100000)) "UTF-8")) + (proxy [InputStream] [] + (read + ([] (throw (IOException. "test error"))) + ([^bytes _] (throw (IOException. "test error"))) + ([^bytes _ _ _] (throw (IOException. "test error"))))))}) ([request response _raise] (response (chunked-stream-with-error request)))) diff --git a/ring-servlet/test/ring/util/test/servlet.clj b/ring-servlet/test/ring/util/test/servlet.clj index f3d917cec..e431b366e 100644 --- a/ring-servlet/test/ring/util/test/servlet.clj +++ b/ring-servlet/test/ring/util/test/servlet.clj @@ -110,27 +110,27 @@ :servlet-context-path "/foo" :ssl-client-cert cert :body body} - response (atom {})] + response (atom {})] (letfn [(handler [r] - (are [k v] (= (r k) v) - :server-port 8080 - :server-name "foobar" - :remote-addr "127.0.0.1" - :uri "/foo" - :query-string "a=b" - :scheme :http - :request-method :get - :protocol "HTTP/1.1" - :headers {"x-client" "Foo,Bar" - "x-server" "Baz" - "x-capital-i" "Qux"} - :content-type "text/plain" - :content-length 10 - :character-encoding "UTF-8" - :servlet-context-path "/foo" - :ssl-client-cert cert - :body body) - {:status 200, :headers {}})] + (are [k v] (= (r k) v) + :server-port 8080 + :server-name "foobar" + :remote-addr "127.0.0.1" + :uri "/foo" + :query-string "a=b" + :scheme :http + :request-method :get + :protocol "HTTP/1.1" + :headers {"x-client" "Foo,Bar" + "x-server" "Baz" + "x-capital-i" "Qux"} + :content-type "text/plain" + :content-length 10 + :character-encoding "UTF-8" + :servlet-context-path "/foo" + :ssl-client-cert cert + :body body) + {:status 200, :headers {}})] (testing "request" (run-servlet handler request response)) (testing "mapping request header names to lower case" @@ -138,10 +138,10 @@ (run-servlet handler request response)))) (testing "response" (letfn [(handler [r] - {:status 200 - :headers {"Content-Type" "text/plain" - "X-Server" "Bar"} - :body "Hello World"})] + {:status 200 + :headers {"Content-Type" "text/plain" + "X-Server" "Bar"} + :body "Hello World"})] (run-servlet handler request response) (is (= (@response :status) 200)) (is (= (@response :content-type) "text/plain")) @@ -191,7 +191,7 @@ (servlet-request request) (servlet-response response)) (is (= (@response :status) 200)) - (is (= (get-in @response [:headers "Content-Type" ]) "text/plain")) + (is (= (get-in @response [:headers "Content-Type"]) "text/plain")) (is (= (.toString (@response :body)) "Hello World")))) (defn- service-handler [_]