ring.middleware和compojure:带关键字的params [英] ring.middleware and compojure: params with keywords
问题描述
在我的网络处理程序中,我定义了以下内容:
In my web handler, I have the following defined:
(:require ...
[ring.middleware.cookies :refer [wrap-cookies]]
[ring.middleware.multipart-params :refer [wrap-multipart-params]]
[ring.middleware.params :refer [wrap-params]]
[ring.middleware.keyword-params :refer [wrap-keyword-params]]
[ring.middleware.content-type :refer [wrap-content-type]]
[ring.middleware.format-response :refer [wrap-restful-response]
...)
(def app
(-> (routes home/my-routes)
(wrap-cookies)
(wrap-params)
(wrap-multipart-params)
(wrap-keyword-params))))
一切正常。使用看起来像../test?foo=123的URL测试curl给我一个看起来像{:foo 123}的params映射。但是,显示为关键字的字符串实际上是一个字符串:(keyword?:foo)返回false。
Everything works. Testing with curl using a URL that looks like "../test?foo=123" gives me a params map that looks like {:foo 123}. However, what appears as a keyword is actually a string: (keyword? :foo) returns false.
我已经尝试重新排列处理程序, ,但无济于事。有什么关于compojure的是将关键字转换回字符串?感谢
I've tried rearranging the handlers and removing them one at a time, but to no avail. Is there something about compojure that is converting the keywords back into strings? Thanks
推荐答案
wrap-keyword-params
code> wrap-params 和 wrap-multipart-params
,因此您的应用程序应如下所示:
wrap-keyword-params
middleware should be run after wrap-params
and wrap-multipart-params
, so your app should look like:
(def app
(-> (routes home/my-routes)
(wrap-keyword-params)
(wrap-cookies)
(wrap-params)
(wrap-multipart-params))))
这篇关于ring.middleware和compojure:带关键字的params的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!