Skip to content

Commit

Permalink
Fix inconsistent formatting with cljfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Oct 19, 2024
1 parent a66fe9e commit 3ef0481
Show file tree
Hide file tree
Showing 26 changed files with 255 additions and 259 deletions.
2 changes: 1 addition & 1 deletion ring-core/src/ring/middleware/cookies.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
38 changes: 19 additions & 19 deletions ring-core/src/ring/middleware/multipart_params/temp_file.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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))))))))
18 changes: 9 additions & 9 deletions ring-core/src/ring/middleware/nested_params.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@
"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
parameters, using the function parse to split the parameter names
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.
Expand Down
28 changes: 14 additions & 14 deletions ring-core/src/ring/middleware/session.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))))))
10 changes: 5 additions & 5 deletions ring-core/src/ring/middleware/session/cookie.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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))))
14 changes: 7 additions & 7 deletions ring-core/src/ring/util/io.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."
Expand Down
6 changes: 3 additions & 3 deletions ring-core/src/ring/util/mime_type.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))
4 changes: 2 additions & 2 deletions ring-core/src/ring/util/request.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
18 changes: 9 additions & 9 deletions ring-core/src/ring/util/response.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion ring-core/test/ring/middleware/test/content_type.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 {})))))
4 changes: 2 additions & 2 deletions ring-core/test/ring/middleware/test/cookies.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}
Expand Down Expand Up @@ -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)))))

Expand Down
14 changes: 7 additions & 7 deletions ring-core/test/ring/middleware/test/file_info.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}))))
Expand Down Expand Up @@ -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]
Expand All @@ -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"
Expand All @@ -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"})))
Expand Down
6 changes: 3 additions & 3 deletions ring-core/test/ring/middleware/test/flash.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions ring-core/test/ring/middleware/test/multipart_params.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ring-core/test/ring/middleware/test/resource.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit 3ef0481

Please sign in to comment.