Skip to content

Commit

Permalink
Don't rely on ring internals.
Browse files Browse the repository at this point in the history
This has the side effect of allowing us to work with ring 1.2.x.
  • Loading branch information
tobias committed Mar 21, 2015
1 parent c9f956f commit 7dc671f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions web/src/immutant/web/internal/headers.clj
Expand Up @@ -12,14 +12,15 @@
;; See the License for the specific language governing permissions and
;; limitations under the License.

(ns ^{:no-doc true}
immutant.web.internal.headers
(:require [clojure.string :as str]
ring.util.request))
(ns ^:no-doc ^:internal
immutant.web.internal.headers
(:require [clojure.string :as str]))

(def charset-pattern (deref #'ring.util.request/charset-pattern))
;; borrowed from ring.util.request/charset-pattern, which appeared in ring 1.3.0.
(def ^:private charset-pattern
#";(?:.*\s)?(?i:charset)=([!#$%&'*\-+.0-9A-Z\^_`a-z\|~]+|\"(\\\"|[^\"])*\")\s*(?:;|$)")

(def default-encoding "ISO-8859-1")
(def ^:private default-encoding "ISO-8859-1")

(defprotocol Headers
(get-names [x])
Expand All @@ -28,13 +29,13 @@
(set-header [x key value])
(add-header [x key value]))

(defn ^String get-character-encoding [headers]
(defn ^:internal ^String get-character-encoding [headers]
(or
(when-let [type (get-value headers "content-type")]
(second (re-find charset-pattern type)))
default-encoding))

(defn headers->map [headers]
(defn ^:internal headers->map [headers]
(persistent!
(reduce
(fn [accum ^String name]
Expand All @@ -46,7 +47,7 @@
(transient {})
(get-names headers))))

(defn write-headers
(defn ^:internal write-headers
[output, headers]
(doseq [[^String k, v] headers]
(if (coll? v)
Expand Down

0 comments on commit 7dc671f

Please sign in to comment.