Skip to content

Commit

Permalink
Use uri to parse forms
Browse files Browse the repository at this point in the history
  • Loading branch information
swlkr committed Feb 12, 2020
1 parent 99fc956 commit d9a8462
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/joy/http.janet
@@ -1,27 +1,15 @@
(import ./helper :as helper)
(import uri)


(def url-decode uri/unescape)


(def url-encode uri/escape)


(defn form-decode [val]
(string/replace-all "+" " " (uri/unescape val)))


(defn parse-body [string-s]
(when (and (string? string-s)
(not (empty? string-s)))
(->> (string/split "&" string-s)
(map |(string/split "=" $))
(flatten)
(apply table)
(helper/map-keys keyword)
(helper/map-vals uri/unescape)
(helper/map-vals form-decode))))
(defn parse-body [str]
(as-> str ?
(string/split "+" ?)
(string/join ? "%20")
(uri/parse-query ?)
(helper/map-keys keyword ?)))


(defn cookie-pair [str]
Expand Down

0 comments on commit d9a8462

Please sign in to comment.