Fork me on GitHub
#ring
<
2018-05-31
>
conan10:05:53

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?

conan10:05:07

I see a failure on the first invocation of my handler function after locating it with reitit routing

conan10:05:58

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 "[email protected]"]

-- 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 "[email protected]"]

-- 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

conan10:05:27

i'm using httpkit

conan10:05:27

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

conan11:05:37

I've just tried with jetty, same result. Both send requests with nil values for :bodyand :query-string

conan11:05:55

So i guess this must be a problem with ring itself?

ikitommi11:05:15

like the response :headers, could all the empty request keys be defined as s/nillable?

conan13:05:59

I also seem to get a missing :protocol from time to time as well

conan13:05:26

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.