File tree Expand file tree Collapse file tree 4 files changed +19
-7
lines changed Expand file tree Collapse file tree 4 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 3
3
* Deprecated : content-type , : content-length and : character-encoding keys in SPEC
4
4
* Removed deprecated keys from source code
5
5
* Added content-length, content-type and character-encoding to ring.util.request
6
+ * Added urlencoded-form? to ring.util.request
6
7
* Fixed 304 not-modified responses to set content-length header
7
8
* Added options to wrap-cookies to specify encoder and decoder functions
8
9
* Fixed wrap-head middleware when response is nil
Original file line number Diff line number Diff line change 18
18
{:query-params params, :params params})
19
19
{:query-params {}, :params {}})))
20
20
21
- (defn- urlencoded-form?
22
- " Does a request have a urlencoded form?"
23
- [request]
24
- (if-let [^String type (req/content-type request)]
25
- (.startsWith type " application/x-www-form-urlencoded" )))
26
-
27
21
(defn assoc-form-params
28
22
" Parse and assoc parameters from the request body with the request."
29
23
{:added " 1.2" }
30
24
[request encoding]
31
25
(merge-with merge request
32
- (if-let [body (and (urlencoded-form? request) (:body request))]
26
+ (if-let [body (and (req/ urlencoded-form? request) (:body request))]
33
27
(let [params (parse-params (slurp body :encoding encoding) encoding)]
34
28
{:form-params params, :params params})
35
29
{:form-params {}, :params {}})))
Original file line number Diff line number Diff line change 37
37
(if-let [type (get-in request [:headers " content-type" ])]
38
38
(second (re-find charset-pattern type))))
39
39
40
+ (defn urlencoded-form?
41
+ " True if a request contains a urlencoded form in the body."
42
+ {:added " 1.3" }
43
+ [request]
44
+ (if-let [^String type (content-type request)]
45
+ (.startsWith type " application/x-www-form-urlencoded" )))
46
+
40
47
(defmulti body-string
41
48
" Return the request body as a string."
42
49
{:arglists '([request]), :added " 1.2" }
Original file line number Diff line number Diff line change 45
45
(is (= (character-encoding {:headers {" content-type" " text/plain;charset=UTF-8" }})
46
46
" UTF-8" ))))
47
47
48
+ (deftest test-urlencoded-form?
49
+ (testing " urlencoded form"
50
+ (is (urlencoded-form? {:headers {" content-type" " application/x-www-form-urlencoded" }}))
51
+ (is (urlencoded-form?
52
+ {:headers {" content-type" " application/x-www-form-urlencoded; charset=UTF-8" }})))
53
+ (testing " other content type"
54
+ (is (not (urlencoded-form? {:headers {" content-type" " application/json" }}))))
55
+ (testing " no content type"
56
+ (is (not (urlencoded-form? {:headers {}})))))
57
+
48
58
(deftest test-body-string
49
59
(testing " nil body"
50
60
(is (= (body-string {:body nil }) nil )))
You can’t perform that action at this time.
0 commit comments