ring

conan 2018-05-31T10:11:53.000207Z

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?

conan 2018-05-31T10:13:07.000092Z

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

conan 2018-05-31T10:14:58.000056Z

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

conan 2018-05-31T10:21:27.000544Z

i'm using httpkit

conan 2018-05-31T10:22:27.000004Z

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

conan 2018-05-31T10:33:39.000323Z

i've raised an issue with httpkit: https://github.com/http-kit/http-kit/issues/377

ikitommi 2018-05-31T11:04:15.000299Z

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

conan 2018-05-31T11:08:37.000392Z

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

conan 2018-05-31T11:08:55.000397Z

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

conan 2018-05-31T13:46:59.000103Z

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

conan 2018-05-31T13:48:26.000358Z

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.