ring-clojure / ring-spec

Clojure specs for Ring
51 stars 7 forks source link

Consistency with servlet implementation #8

Open mtkp opened 5 years ago

mtkp commented 5 years ago

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](https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getQueryString()) method.

mtkp commented 5 years ago

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