johanhaleby / stub-http

Client library agnostic way to stub HTTP endpoints in Clojure
MIT License
70 stars 10 forks source link

NullPointerException when stubbing endpoint with no body #21

Closed roberttaylor426 closed 2 years ago

roberttaylor426 commented 2 years ago

Hi,

Thanks for the great library!

Having updated to version 0.2.13 from 0.2.12 I'm now seeing an NPE when stubbing a server that only returns status 500, with no body specified. For example:

(stub/start! {{:method :post :path "/api/foo"} {:status 500}})

yields:

java.lang.NullPointerException
at stub_http.internal.server$create_response.invokeStatic(server.clj:42)
at stub_http.internal.server$create_response.invoke(server.clj:24)
at stub_http.internal.server$new_server_BANG_$fn__38653.invoke(server.clj:106)
at stub_http.internal.server.proxy$fi.iki.elonen.NanoHTTPD$ff19274a.serve(Unknown Source)
at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)
at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)
at java.lang.Thread.run(Thread.java:750)

If I provide an empty body, there is no exception. Is specifying a body now mandatory?

Thanks!

johanhaleby commented 2 years ago

Hi! Thanks for finding and reporting this. To my mind, this shouldn't have changed (but it obviously has), so I think it's a bug. I would be really grateful if you could provide a pull request, then I'll make a new release asap :)