ring-spec icon indicating copy to clipboard operation
ring-spec copied to clipboard

Consistency with servlet implementation

Open mtkp opened this issue 6 years ago • 1 comments
trafficstars

Seems like there is an inconsistency between the :ring/request spec and the servlet implementation, in particular the map created by build-request-map. This is based on my assumption that the request handed to my handler from ring jetty server, for example, should satisfy the :ring/request spec.

The spec says the :query-string key is optional but the value must be a string? and the implementation returns the :query-string key always but sometimes a null (nil) value via the .getQueryString method.

mtkp avatar May 16 '19 19:05 mtkp

Repro:

;; deps.edn
{:deps {org.clojure/spec.alpha {:mvn/version "0.2.176"}
        ring/ring-jetty-adapter {:mvn/version "1.7.1"}
        ring/ring-spec {:mvn/version "0.0.4"}}}

;; src/main.clj
(ns main
  (:require
    [clojure.spec.alpha :as s]
    [ring.adapter.jetty :as jetty]
    [ring.core.spec]))

(defn handler [request]
  (when-not (s/valid? :ring/request request)
    (s/explain :ring/request request)
    (flush))
  {:status 200 :body "ok"})

(defn -main [& args]
  (jetty/run-jetty handler {:port 34567}))
clj -m main
curl localhost:34567

mtkp avatar May 16 '19 20:05 mtkp