Skip to content

Commit

Permalink
Add can-put-to-missing? as a decision point
Browse files Browse the repository at this point in the history
* Return not-implemented (501) if put-to-missing? evaluates to false
  • Loading branch information
ordnungswidrig committed Jan 6, 2013
1 parent 6f59263 commit 76490e5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/liberator/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@

(defdecision ^{:step [:O14 :P3]} conflict? handle-conflict put!)

(defdecision put-to-different-url? handle-moved-permamently conflict?)
(defhandler handle-not-implemented 501 "Not implemented.")

(defdecision can-put-to-missing? conflict? handle-not-implemented)

(defdecision put-to-different-url? handle-moved-permamently can-put-to-missing?)

(defdecision method-put? (partial =method :put) put-to-different-url? existed?)

Expand Down Expand Up @@ -392,7 +396,7 @@
((get-in ctx [:resource :available-encodings]) ctx))]
{:representation {:encoding encoding}}))

exists? handle-not-acceptable)
exists? handle-not-acceptable)

(defmacro try-header [header & body]
`(try ~@body
Expand Down Expand Up @@ -466,7 +470,6 @@
(defhandler handle-unsupported-media-type 415 "Unsupported media type.")
(defdecision known-content-type? valid-entity-length? handle-unsupported-media-type)

(defhandler handle-not-implemented 501 "Not implemented.")
(defdecision valid-content-header? known-content-type? handle-not-implemented)

(defhandler handle-forbidden 403 "Forbidden.")
Expand Down Expand Up @@ -515,6 +518,7 @@
:multiple-representations? false
:conflict? false
:can-post-to-missing? true
:can-put-to-missing? true
:moved-permanently? false
:moved-temporarily? false
:delete-enacted? true
Expand Down Expand Up @@ -573,7 +577,8 @@
*-logger* var-logger]
(let [resp (handler request)]
(when resp
(assoc-in resp [:headers "X-Liberator-Trace"] (make-trace-headers @*-log*)))))))
(assoc-in resp
[:headers "X-Liberator-Trace"] (make-trace-headers @*-log*)))))))

(defn get-trace []
(make-trace-headers @*-log*))
2 changes: 2 additions & 0 deletions test/checkers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@
(def GONE (is-status 410))
(def PRECONDITION-FAILED (is-status 412))

(def NOT-IMPLEMENTED (is-status 501))

11 changes: 11 additions & 0 deletions test/test_flow.clj
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,14 @@
resp (r (request :post "/")) ]
(fact "Post to existing if post to missing forbidden is allowed" resp => CREATED))

(let [r (resource :method-allowed? [:put]
:exists? false
:can-put-to-missing? false)
resp (r (request :put "/"))]
(fact "Put to missing can give 501" resp => NOT-IMPLEMENTED))

(let [r (resource :method-allowed? [:put]
:exists? false
:can-put-to-missing? true)
resp (r (request :put "/"))]
(fact "Put to missing can give 201" resp => CREATED))

0 comments on commit 76490e5

Please sign in to comment.