|
59 | 59 | (apply (ns-resolve (symbol "crouton.html") (symbol "parse")) args)) |
60 | 60 |
|
61 | 61 | (defn ^:dynamic parse-transit |
62 | | - "Resolve and apply Transit's JSON/MessagePack parsing." |
63 | | - [& args] |
| 62 | + "Resolve and apply Transit's JSON/MessagePack decoding." |
| 63 | + [in type & [opts]] |
64 | 64 | {:pre [transit-enabled?]} |
65 | 65 | (let [reader (ns-resolve 'cognitect.transit 'reader) |
66 | 66 | read (ns-resolve 'cognitect.transit 'read)] |
67 | | - (read (apply reader args)))) |
| 67 | + (read (reader in type opts)))) |
| 68 | + |
| 69 | +(defn ^:dynamic transit-encode |
| 70 | + "Resolve and apply Transit's JSON/MessagePack encoding." |
| 71 | + [out type & [opts]] |
| 72 | + {:pre [transit-enabled?]} |
| 73 | + (let [output (java.io.ByteArrayOutputStream.) |
| 74 | + writer (ns-resolve 'cognitect.transit 'writer) |
| 75 | + write (ns-resolve 'cognitect.transit 'write)] |
| 76 | + (write (writer output type opts) out) |
| 77 | + (.toByteArray output))) |
68 | 78 |
|
69 | 79 | (defn ^:dynamic json-encode |
70 | 80 | "Resolve and apply cheshire's json encoding dynamically." |
|
642 | 652 | :form-params form-params |
643 | 653 | :transit-opts transit-opts |
644 | 654 | :transit-type type}))) |
645 | | - (let [output (java.io.ByteArrayOutputStream.) |
646 | | - writer (ns-resolve 'cognitect.transit 'writer) |
647 | | - write (ns-resolve 'cognitect.transit 'write) |
648 | | - _ (write (writer output type transit-opts) form-params) |
649 | | - bytes (.toByteArray output)] |
650 | | - (.reset output) |
651 | | - bytes)) |
| 655 | + (transit-encode form-params type transit-opts)) |
652 | 656 |
|
653 | 657 | (defmethod coerce-form-params :application/transit+json [req] |
654 | 658 | (coerce-transit-form-params :json req)) |
|
701 | 705 | (defn wrap-nested-params |
702 | 706 | "Middleware wrapping nested parameters for query strings." |
703 | 707 | [client] |
704 | | - (fn [{:keys [query-params form-params content-type] :as req}] |
705 | | - (if (= :json content-type) |
706 | | - (client req) |
| 708 | + (fn [{:keys [query-params form-params content-type] |
| 709 | + :as req}] |
| 710 | + (if (or (nil? content-type) |
| 711 | + (= content-type :x-www-form-urlencoded)) |
707 | 712 | (client (reduce |
708 | 713 | nest-params |
709 | 714 | req |
710 | | - [:query-params :form-params]))))) |
| 715 | + [:query-params :form-params])) |
| 716 | + (client req)))) |
711 | 717 |
|
712 | 718 | (defn wrap-url |
713 | 719 | "Middleware wrapping request URL parsing." |
|
0 commit comments