Skip to content

Commit

Permalink
Converted ring-core to use new meta syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Jul 16, 2010
1 parent e724e0a commit 173cb2d
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion ring-core/src/ring/middleware/cookies.clj
Expand Up @@ -39,7 +39,7 @@
[cookies]
(for [[name value] cookies]
(let [value (url-decode value)]
(if (.startsWith #^String value "\"")
(if (.startsWith ^String value "\"")
[name (read-string value)]
[name value]))))

Expand Down
4 changes: 2 additions & 2 deletions ring-core/src/ring/middleware/file.clj
Expand Up @@ -8,15 +8,15 @@

(defn- ensure-dir
"Ensures that a directory exists at the given path, throwing if one does not."
[#^String dir-path]
[^String dir-path]
(let [dir (File. dir-path)]
(throw-if-not (.exists dir) "Directory does not exist: %s" dir-path)))

(defn wrap-file
"Wrap an app such that the directory at the given root-path is checked for a
static file with which to respond to the request, proxying the request to the
wrapped app if such a file does not exist."
[app #^String root-path]
[app ^String root-path]
(ensure-dir root-path)
(fn [req]
(if-not (= :get (:request-method req))
Expand Down
8 changes: 4 additions & 4 deletions ring-core/src/ring/middleware/file_info.clj
Expand Up @@ -64,13 +64,13 @@

(defn- get-extension
"Returns the file extension of a file."
[#^File file]
[^File file]
(second (re-find #"\.([^./\\]+)$" (.getPath file))))

(defn- guess-mime-type
"Returns a String corresponding to the guessed mime type for the given file,
or application/octet-stream if a type cannot be guessed."
[#^File file mime-types]
[^File file mime-types]
(get mime-types (get-extension file) "application/octet-stream"))

(defn make-http-format
Expand Down Expand Up @@ -100,8 +100,8 @@
(let [{:keys [headers body] :as response} (app req)]
(if (instance? File body)
(let [file-type (guess-mime-type body mime-types)
file-length (.length #^File body)
lmodified (Date. (.lastModified #^File body))
file-length (.length ^File body)
lmodified (Date. (.lastModified ^File body))
response (-> response
(content-type file-type)
(header "Last-Modified"
Expand Down
8 changes: 4 additions & 4 deletions ring-core/src/ring/middleware/multipart_params.clj
Expand Up @@ -11,10 +11,10 @@
(defn- multipart-form?
"Does a request have a multipart form?"
[request]
(if-let [#^String content-type (:content-type request)]
(if-let [^String content-type (:content-type request)]
(.startsWith content-type "multipart/form-data")))

(defvar- #^FileUpload file-upload
(defvar- ^FileUpload file-upload
(FileUpload.
(doto (DiskFileItemFactory.)
(.setSizeThreshold -1)
Expand All @@ -33,7 +33,7 @@

(defn- file-map
"Create a file map from a DiskFileItem."
[#^DiskFileItem item]
[^DiskFileItem item]
(with-meta
{:filename (.getName item)
:size (.getSize item)
Expand All @@ -45,7 +45,7 @@
"Parse a map of multipart parameters from the request."
[request encoding]
(reduce
(fn [param-map, #^DiskFileItem item]
(fn [param-map, ^DiskFileItem item]
(assoc-param param-map
(.getFieldName item)
(if (.isFormField item)
Expand Down
4 changes: 2 additions & 2 deletions ring-core/src/ring/middleware/params.clj
Expand Up @@ -16,7 +16,7 @@

(defn- parse-params
"Parse parameters from a string into a map."
[#^String param-string encoding]
[^String param-string encoding]
(reduce
(fn [param-map encoded-param]
(if-let [[_ key val] (re-matches #"([^=]+)=(.*)" encoded-param)]
Expand All @@ -39,7 +39,7 @@
(defn- urlencoded-form?
"Does a request have a urlencoded form?"
[request]
(if-let [#^String type (:content-type request)]
(if-let [^String type (:content-type request)]
(.startsWith type "application/x-www-form-urlencoded")))

(defn- assoc-form-params
Expand Down
4 changes: 2 additions & 2 deletions ring-core/src/ring/middleware/session/cookie.clj
Expand Up @@ -59,7 +59,7 @@
[options]
(if-let [secret-key (:key options)]
(if (string? secret-key)
(.getBytes #^String secret-key)
(.getBytes ^String secret-key)
secret-key)
(secure-random-bytes 16)))

Expand All @@ -71,7 +71,7 @@

(defn- unseal
"Retrieve a sealed Clojure data structure from a string"
[key #^String string]
[key ^String string]
(let [[data mac] (.split string "--")
data (codec/base64-decode data)]
(if (= mac (hmac key data))
Expand Down
2 changes: 1 addition & 1 deletion ring-core/src/ring/middleware/static.clj
Expand Up @@ -12,7 +12,7 @@
[app public-dir statics]
(let [app-with-file (wrap-file app public-dir)]
(fn [req]
(let [#^String uri (:uri req)]
(let [^String uri (:uri req)]
(if (some #(.startsWith uri %) statics)
(app-with-file req)
(app req))))))
2 changes: 1 addition & 1 deletion ring-core/src/ring/util/codec.clj
Expand Up @@ -23,5 +23,5 @@

(defn base64-decode
"Decode a base64 encoded string into an array of bytes."
[#^String encoded]
[^String encoded]
(Base64/decodeBase64 (.getBytes encoded)))
10 changes: 5 additions & 5 deletions ring-core/src/ring/util/response.clj
Expand Up @@ -19,23 +19,23 @@

(defn- safe-path?
"Is a filepath safe for a particular root?"
[#^String root #^String path]
[^String root ^String path]
(.startsWith (.getCanonicalPath (File. root path))
(.getCanonicalPath (File. root))))

(defn- find-index-file
"Search the directory for an index file."
[#^File dir]
[^File dir]
(first
(filter
#(.startsWith (.toLowerCase (.getName #^File %)) "index.")
#(.startsWith (.toLowerCase (.getName ^File %)) "index.")
(.listFiles dir))))

(defn- get-file
"Safely retrieve the correct file. See file-response for an
explanation of options."
[#^String path opts]
(if-let [file (if-let [#^String root (:root opts)]
[^String path opts]
(if-let [file (if-let [^String root (:root opts)]
(and (safe-path? root path) (File. root path))
(File. path))]
(cond
Expand Down
2 changes: 1 addition & 1 deletion ring-core/src/ring/util/test.clj
Expand Up @@ -2,6 +2,6 @@
"Utilities for testing Ring components."
(:import (java.io ByteArrayInputStream)))

(defn string-input-stream [#^String s]
(defn string-input-stream [^String s]
"Returns a ByteArrayInputStream for the given String."
(ByteArrayInputStream. (.getBytes s)))

0 comments on commit 173cb2d

Please sign in to comment.