-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Labels
Description
When no content-type is provided but JSON is POSTed, the :body
of the request becomes nil
instead of something like InputStream / string.
Steps to reproduce
Given a new Luminus app generated with +service
(which uses muuntaja "0.6.4") and these service-routes
:
(defn service-routes []
["/api"
{:coercion spec-coercion/coercion
:muuntaja formats/instance
:swagger {:id ::api}
:middleware [parameters/parameters-middleware
muuntaja/format-negotiate-middleware
muuntaja/format-response-middleware
exception/exception-middleware
muuntaja/format-request-middleware
coercion/coerce-response-middleware
coercion/coerce-request-middleware
multipart/multipart-middleware]}
["/employee"
{:swagger {:tags ["employee"]}}
["/start"
{:post {
:parameters {:body map?}
:responses {200 {:body string?}}
:handler (fn [{{body :body} :parameters}]
{:status 200
:headers {"Content-Type" "application/json"}
:body {:message "Hi back!"}})}}]]])
and this request:
;; myapp.handler ns:
(do
(require '[jsonista.core :as json])
(import java.io.ByteArrayInputStream)
((app)
{:headers {"accept" "application/json"}
:uri "/api/employee/start"
:request-method :post
:body (ByteArrayInputStream.
(json/write-value-as-bytes
{:first-name "Bo"}))}))
it fails with
Request coercion failed ... #:clojure.spec.alpha{:problems ({:path [], :pred clojure.core/map?, :val nil, :via [], :in []})
If I modify the request headers to include "content-type" "application/json"
then it works.