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

Request with PATCH method do not include the body in the request structure. #12

Open
jsofra opened this issue Jul 15, 2020 · 5 comments

Comments

@jsofra
Copy link

jsofra commented Jul 15, 2020

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)})})]
...
)
@johanhaleby
Copy link
Owner

johanhaleby commented Jul 15, 2020

@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.

@jsofra
Copy link
Author

jsofra commented Jul 15, 2020

@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 :)

@johanhaleby
Copy link
Owner

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.

@jsofra
Copy link
Author

jsofra commented Jul 15, 2020

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.

@johanhaleby
Copy link
Owner

johanhaleby commented Jul 15, 2020 via email

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

No branches or pull requests

2 participants