Skip to content

:body is nil when correct "content-type" header not provided #104

@holyjak

Description

@holyjak

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions