Fork me on GitHub
#pedestal
<
2022-03-02
>
zeitstein18:03:29

I'm seeing unexpected behaviour, but I'm not sure if it warrants opening an issue. If the content-type request header is specified as anything other than "Content-Type" (e.g. "content-type"), the value of :content-type is an empty string in (:request context). Perhaps related to https://github.com/pedestal/pedestal/issues/681? I'll share a reproducible example in the thread.

zeitstein18:03:46

(ns server.issue
  (:require
   [io.pedestal.http :as http]
   [io.pedestal.test :as test]
   [io.pedestal.http.route :as route]))

(def echo
  {:name ::echo
   :enter
   (fn [context]
     (let [request (:request context)
           ;; to enable read-string
           request* (dissoc request
                      :servlet-response
                      :servlet
                      :servlet-request
                      :body
                      :url-for)]
       (assoc context :response
         {:status 200 :body request*})))})

(def routes
  (route/expand-routes #{["/echo" :get [echo]]}))

(def service-map
  {::http/routes routes
   ::http/type   :jetty
   ::http/port   8080})

(defonce server (atom nil))

(defn start-dev []
  (reset! server
    (-> service-map
      (assoc ::http/join? false)
      http/create-server
      http/start)))

(defn stop-dev []
  (http/stop @server))

(defn restart []
  (stop-dev)
  (start-dev))

(comment
  (stop-dev)
  (start-dev)
  (restart)

  (-> (test/response-for (:io.pedestal.http/service-fn @server) :get "/echo"
        :headers {"content-type" "text/html"})
    :body
    read-string
    :content-type)

  (-> (test/response-for (:io.pedestal.http/service-fn @server) :get "/echo"
        :headers {"Content-Type" "text/html"})
    :body
    read-string
    :content-type)
  ;
  )