Skip to content

Commit

Permalink
Merge pull request #181 from psagers/master
Browse files Browse the repository at this point in the history
Fix #156: Look for (dyn :response-code) in spork/httpf
  • Loading branch information
bakpakin authored Apr 21, 2024
2 parents 19787cc + b703a97 commit 1801872
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions spork/httpf.janet
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,15 @@
(setdyn :response-headers response-headers)
(case method
"GET" (try
(make-response
200
(do
(def query (get req :query {}))
(def raw-post-data (get query "data"))
(def post-data (if raw-post-data (parse raw-post-data)))
(when-let [validate (get schemas path)]
(validate post-data))
(setdyn :data post-data)
(handler req post-data)))
(do
(def query (get req :query {}))
(def raw-post-data (get query "data"))
(def post-data (if raw-post-data (parse raw-post-data)))
(when-let [validate (get schemas path)]
(validate post-data))
(setdyn :data post-data)
(let [content (handler req post-data)]
(make-response (dyn :response-code 200) content)))
([err f]
(make-400-response (string err) f)))
"OPTIONS" {:status 200
Expand All @@ -241,13 +240,16 @@
body)]
(setdyn :data data)
(try
(make-response 200 (do (if validate (validate data)) (handler req data)))
(do
(when validate (validate data))
(let [content (handler req data)]
(make-response (dyn :response-code 200) content)))
([err f] (make-400-response (string err) f))))
(make-response 405 "Method not allowed. Use GET, OPTIONS, or POST.")))
([err f]
(eprint "internal server error: " (string err) f)
(debug/stacktrace (fiber/current))
(make-response 500 err))))
([err f]
(eprint "internal server error: " (string err) f)
(debug/stacktrace (fiber/current))
(make-response 500 err))))

(put state :on-connection
(fn connection-handler [conn]
Expand Down Expand Up @@ -281,4 +283,3 @@
(repeat n-workers (ev-utils/spawn-nursery n (forever (on-connection (ev/take q)))))
(ev-utils/join-nursery n))))
(print "server closed"))

0 comments on commit 1801872

Please sign in to comment.