stub-http
stub-http copied to clipboard
Request with PATCH method do not include the body in the request structure.
When stubbing a PATCH method request the stub-request returned from the nano server has no body. This means tests that rely on the body for generating a response for PATCH request cannot be written.
e.g.
(with-open [server (start! {{:path "/mypath" :method :patch}
(fn [request]
{:status 200
;; the request has a nil body
:body (:body request)})})]
...
)
@jsofra :/ Thanks for reporting, Could be a limitation of nanohttpd. Do you know or recommend a small simple http server that is still maintained? Maybe we can switch it instead.
@johanhaleby thanks for the reply. I dug into nanohttpd and it does seem to be a limitation ... https://github.com/NanoHttpd/nanohttpd/blob/efb2ebf85a2b06f7c508aba9eaad5377e3a01e81/core/src/main/java/org/nanohttpd/protocols/http/HTTPSession.java#L639
As far are small simple http servers I am not sure. I guess there is always Jetty, not that it is that small, or possibly http-kit.
Anyway, it is a nice library, thanks :)
I accidentally wrote "Maybe you can switch it instead" instead of "Maybe we can switch it instead". Sorry about that, it was not my intension :)
Thanks for digging in to nanohttpd. Maybe switching to something more mainstream like jetty or undertow would make sense. Presumable we won't find limitations like this so it could be worth the extra library size.
I ended up just going with this using jetty:
(require '[ring.adapter.jetty :as jetty])
(require '[reitit.ring :as ring])
(require '[clj-http.client :as client])
(defn start-server [routes options]
(jetty/run-jetty (ring/ring-handler (ring/router routes)) (merge {:join? false} options)))
(defmacro with-server [options routes & body]
`(let [server# (start-server ~routes ~options)]
(try
~@body
(finally (.stop server#)))))
(with-server {:port 3000}
[["/my/route" (fn [_]
{:status 200
:body "hello"})]]
(client/get "http://localhost:3000/my/route" {}))
Not very sophisticated but got the job done.
Yes, works perfectly well :) Glad you found a workaround and thanks for sharing.
On Wed, Jul 15, 2020 at 3:09 PM James Sofra [email protected] wrote:
I ended up just going with this using jetty:
(require '[ring.adapter.jetty :as jetty]) (require '[reitit.ring :as ring]) (require '[clj-http.client :as client])
(defn start-server [routes options] (jetty/run-jetty (ring/ring-handler (ring/router routes)) (merge {:join? false} options)))
(defmacro with-server [options routes & body] `(let [server# (start-server ~routes ~options)] (try ~@body (finally (.stop server#)))))
(with-server {:port 3000} [["/my/route" (fn [_] {:status 200 :body "hello"})]] (client/get "http://localhost:3000/my/route" {}))
Not very sophisticated but got the job done.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/johanhaleby/stub-http/issues/12#issuecomment-658757419, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABNVFM64MQJPYQTCM6NK43R3WTBVANCNFSM4O2C5WDQ .