Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
holyjak opened this issue Sep 18, 2019 · 1 comment
Open

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

holyjak opened this issue Sep 18, 2019 · 1 comment

Comments

@holyjak
Copy link

holyjak commented Sep 18, 2019

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.

@ikitommi ikitommi added the bug label Sep 18, 2019
@ikitommi
Copy link
Member

PR welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants