Clojure 如何在REITT中将原始标头参数设置为必需的?
我有一个带有Destale&Reitt的Clojure应用程序,我需要origin header参数是必需的Clojure 如何在REITT中将原始标头参数设置为必需的?,clojure,reitit,Clojure,Reitit,我有一个带有Destale&Reitt的Clojure应用程序,我需要origin header参数是必需的 ;; deps [io.pedestal/pedestal.service "0.5.5"] [pedestal/pedestal.jetty "0.5.5"] [reitit-pedestal "0.5.5"] [reitit "0.5.5"] 但是,如果我在模式中输入,请求将抛出一个异常 (s/defs
;; deps
[io.pedestal/pedestal.service "0.5.5"]
[pedestal/pedestal.jetty "0.5.5"]
[reitit-pedestal "0.5.5"]
[reitit "0.5.5"]
但是,如果我在模式中输入,请求将抛出一个异常
(s/defschema my-request
{:header {:origin s/Str}})
["/my-route"
{:get {:parameters my-request
:handler my-handler}}]
例外情况:
:错误{:origin缺少所需密钥}
{
"message": "Bad Request",
"exception": "clojure.lang.ExceptionInfo: clojure.lang.ExceptionInfo in Interceptor :reitit.http.coercion/coerce-request -
Request coercion failed: #reitit.coercion.CoercionError{:schema {:origin java.lang.String, Keyword Any}, :errors {:origin missing-required-key}}
请求
curl -X GET "http://localhost:3000/my-route -H "accept: application/json" "origin: TEST" -H "user-agent: test"
CURL请求有效,问题只出现在带有GET方法的Swagger UI中。
看来,为了避免cors的攻击,Gigger for get方法不会发送origin头参数
我能解决这个问题吗
谢谢你的帮助在我与一位同事讨论后,他向我展示了: 原始请求标头指示提取从何处开始。它不包含任何路径信息,只包含服务器名称。它与CORS请求以及POST请求一起发送。它类似于Referer头,但与此头不同,它不公开整个路径 我发现了这个 禁止的标头名称是无法通过编程方式修改的任何HTTP标头的名称;具体来说,HTTP请求头名称(与禁止响应头名称相反) 猜猜看,起源就是其中之一 我也要这个。 不应为GET和HEAD请求设置原始标头 2年前(2018-11-20) 我在firefox和chrome中尝试并检查了我的应用程序请求,它们的行为等同于链接
我想就是这样。谢谢请求中断是什么意思?请添加错误/stacktraces/。。。对问题的回答是“但是如果我把我的模式放进去,这个请求会抛出一个异常”,更好吗?我注意到卷曲请求是有效的,问题只是在摇摇欲坠的UI中。有人考虑过吗?