-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsing.clj
34 lines (29 loc) · 1.07 KB
/
parsing.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(ns ring.util.parsing
"Regular expressions for parsing HTTP.
For internal use."
{:author "James Reeves"
:contributors "Modified by Carlos da Cunha Fontes to work with Babashka"
:url "https://github.com/ring-clojure/ring"
:license {:name "Distributed under the MIT License, the same as Ring."}})
(def ^{:doc "HTTP token: 1*<any CHAR except CTLs or tspecials>. See RFC2068"
:added "1.3"}
re-token
#"[!#$%&'*\-+.0-9A-Z\^_`a-z\|~]+")
(def ^{:doc "HTTP quoted-string: <\"> *<any TEXT except \"> <\">. See RFC2068."
:added "1.3"}
re-quoted
#"\"((?:\\\"|[^\"])*)\"")
(def ^{:doc "HTTP value: token | quoted-string. See RFC2109"
:added "1.3"}
re-value
(str "(" re-token ")|" re-quoted))
(def ^{:doc "Pattern for pulling the charset out of the content-type header"
:added "1.6"}
re-charset
(re-pattern (str ";(?:.*\\s)?(?i:charset)=(?:" re-value ")\\s*(?:;|$)")))
(defn find-content-type-charset
"Return the charset of a given a content-type string."
{:added "1.8.1"}
[s]
(when-let [m (re-find re-charset s)]
(or (m 1) (m 2))))