Permalink
Please sign in to comment.
Browse files
Factor base64 and url encoding/decoding into ring.util.codec.
- Loading branch information...
Showing
with
31 additions
and 35 deletions.
9
ring-core/src/ring/middleware/file.clj
15
ring-core/src/ring/middleware/params.clj
23
ring-core/src/ring/middleware/session/cookie.clj
19
ring-core/src/ring/util/codec.clj
| @@ -0,0 +1,19 @@ | ||
| +(ns ring.util.codec | ||
| + (:import java.io.File java.net.URLDecoder | ||
| + org.apache.commons.codec.binary.Base64)) | ||
| + | ||
| +(defn url-decode | ||
| + "Returns the form-url-decoded version of the given string, using either a | ||
| + specified encoding or UTF-8 by default." | ||
| + [encoded & [encoding]] | ||
| + (URLDecoder/decode encoded (or encoding "UTF-8"))) | ||
| + | ||
| +(defn base64-encode | ||
| + "Encode an array of bytes into a base64 encoded string." | ||
| + [unencoded] | ||
| + (String. (Base64/encodeBase64 unencoded))) | ||
| + | ||
| +(defn base64-decode | ||
| + "Decode a base64 encoded string into an array of bytes." | ||
| + [encoded] | ||
| + (Base64/decodeBase64 (.getBytes encoded))) |
0 comments on commit
15fc2b6