Skip to content

Commit

Permalink
add teapot functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaCrotti committed Jun 26, 2024
1 parent a13015c commit afbf4ed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/ring/util/http_response.clj
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,32 @@
:headers {}
:body body})))

(defn im-a-teapot
"418 I'm a teapot (ClientError)
Any attempt to brew coffee with a teapot should result in the error
code \"418 I'm a teapot\". The resulting entity body MAY be short and
stout. "
([] (expectation-failed nil))
([body]
{:status 418
:headers {}
:body body}))

(defn im-a-teapot!
"418 I'm a teapot (ClientError)
Any attempt to brew coffee with a teapot should result in the error
code \"418 I'm a teapot\". The resulting entity body MAY be short and
stout.
Throws an exception with ex-info:
{:type :ring.util.http-response/response
:response response}"
([] (expectation-failed! nil))
([body]
(throw!
{:status 418
:headers {}
:body body})))

(defn enhance-your-calm
"420 Enhance Your Calm (ClientError)
You are being rate-limited."
Expand Down Expand Up @@ -1122,7 +1148,7 @@

(defn network-read-timeout!
"598 Network read timeout (ServerError)
Throws an exception with ex-info:
{:type :ring.util.http-response/response
:response response}"
Expand All @@ -1144,7 +1170,7 @@

(defn network-connect-timeout!
"599 Network connect timeout (ServerError)
Throws an exception with ex-info:
{:type :ring.util.http-response/response
:response response}"
Expand Down Expand Up @@ -1228,4 +1254,3 @@
(if-not (ns-resolve 'ring.util.response 'get-charset)
(println "Can't import ring.util.response/get-charset, try updating to Ring 1.6.0+"))
(p/import-vars [ring.util.response get-charset])

2 changes: 2 additions & 0 deletions test/ring/util/http_response_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
(is (= {:status 415 :headers {} :body "body"} (unsupported-media-type "body")))
(is (= {:status 416 :headers {} :body "body"} (requested-range-not-satisfiable "body")))
(is (= {:status 417 :headers {} :body "body"} (expectation-failed "body")))
(is (= {:status 418 :headers {} :body "body"} (im-a-teapot "body")))
(is (= {:status 420 :headers {} :body "body"} (enhance-your-calm "body")))
(is (= {:status 422 :headers {} :body "body"} (unprocessable-entity "body")))
(is (= {:status 423 :headers {} :body "body"} (locked "body")))
Expand Down Expand Up @@ -120,6 +121,7 @@
(is (slingshots? {:status 415 :headers {} :body "body"} (unsupported-media-type! "body")))
(is (slingshots? {:status 416 :headers {} :body "body"} (requested-range-not-satisfiable! "body")))
(is (slingshots? {:status 417 :headers {} :body "body"} (expectation-failed! "body")))
(is (slingshots? {:status 418 :headers {} :body "body"} (im-a-teapot! "body")))
(is (slingshots? {:status 420 :headers {} :body "body"} (enhance-your-calm! "body")))
(is (slingshots? {:status 422 :headers {} :body "body"} (unprocessable-entity! "body")))
(is (slingshots? {:status 423 :headers {} :body "body"} (locked! "body")))
Expand Down

0 comments on commit afbf4ed

Please sign in to comment.