Hi, I'm using ring-defaults
middleware to get the ring.middleware.params/wrap-params
(I'm also using munntaja.middleware/wrap-format
), and these seem to be adding in nil
values for :body
(and :query-string
respectively). This stops the requests being ring-spec compliant, as these keys are not nilable
- is there a way to get wrap-params
to remove the key instead of adding in a nil
value to keep the request spec-compliant?
I see a failure on the first invocation of my handler function after locating it with reitit routing
Here's my error (via expound):
Call to #'hanabi.web/initialise did not conform to spec:
web.clj:181
-- Spec failed --------------------
Function arguments
({:reitit.core/match ...,
:reitit.core/router ...,
:remote-addr ...,
:params ...,
:headers ...,
:async-channel ...,
:server-port ...,
:content-length ...,
:form-params ...,
:websocket? ...,
:web/session ...,
:query-params ...,
:content-type ...,
:character-encoding ...,
:uri ...,
:server-name ...,
:query-string ...,
:path-params ...,
:body nil,
^^^
:scheme ...,
:request-method ...})
should satisfy
#object[clojure.spec.alpha$regex_spec_impl$reify__2436 0x765709fc "clojure.spec.alpha$regex_spec_impl$reify__2436@765709fc"]
-- Relevant specs -------
:ring.request/body:
:clojure.spec.alpha/unknown
:ring/request:
(clojure.spec.alpha/keys
:req-un
[:ring.request/server-port
:ring.request/server-name
:ring.request/remote-addr
:ring.request/uri
:ring.request/scheme
:ring.request/protocol
:ring.request/headers
:ring.request/request-method]
:opt-un
[:ring.request/query-string :ring.request/body])
:web.ring/request:
(clojure.spec.alpha/merge
:ring/request
(clojure.spec.alpha/keys
:req
[:web/session]
:req-un
[:web.ring.request/edn-params]))
-- Spec failed --------------------
Function arguments
({:reitit.core/match ...,
:reitit.core/router ...,
:remote-addr ...,
:params ...,
:headers ...,
:async-channel ...,
:server-port ...,
:content-length ...,
:form-params ...,
:websocket? ...,
:web/session ...,
:query-params ...,
:content-type ...,
:character-encoding ...,
:uri ...,
:server-name ...,
:query-string nil,
^^^
:path-params ...,
:body ...,
:scheme ...,
:request-method ...})
should satisfy
#object[clojure.spec.alpha$regex_spec_impl$reify__2436 0x765709fc "clojure.spec.alpha$regex_spec_impl$reify__2436@765709fc"]
-- Relevant specs -------
:ring.request/query-string:
:clojure.spec.alpha/unknown
:ring/request:
(clojure.spec.alpha/keys
:req-un
[:ring.request/server-port
:ring.request/server-name
:ring.request/remote-addr
:ring.request/uri
:ring.request/scheme
:ring.request/protocol
:ring.request/headers
:ring.request/request-method]
:opt-un
[:ring.request/query-string :ring.request/body])
:web.ring/request:
(clojure.spec.alpha/merge
:ring/request
(clojure.spec.alpha/keys
:req
[:web/session]
:req-un
[:web.ring.request/edn-params]))
-------------------------
Detected 2 errors
i'm using httpkit
it appears that the request that reaches my handler contains the :body
and :query-string
keys both with nil
values, so the problem is not with middleware, sorry
i've raised an issue with httpkit: https://github.com/http-kit/http-kit/issues/377
like the response :headers
, could all the empty request keys be defined as s/nillable
?
I've just tried with jetty, same result. Both send requests with nil
values for :body
and :query-string
So i guess this must be a problem with ring itself?
The spec: https://github.com/ring-clojure/ring-spec/blob/master/src/ring/core/spec.clj#L115
I also seem to get a missing :protocol
from time to time as well
I actually think the spec is good here, I don't see the point of including nil
values in maps, but at the moment it seems pretty unusable because I can't find anywhere to get a valid ring request.