Created
April 3, 2014 15:10
-
-
Save sritchie/9956196 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns paddleguru.middleware.request-method | |
(:require [clojure.string :as st])) | |
(defn ensure-request-method | |
"Middleware to ensure that the request method is properly processed | |
out of the form params. Without this, any ':delete' post that hits a | |
liberator endpoint will be processed as a :post. | |
(Compojure only processes this form-params field when you explicitly | |
list a route as (DELETE theroute [] handler).)" | |
[handler] | |
(fn [request] | |
(handler | |
(if-let [method (get-in request [:form-params "_method"])] | |
(assoc request :request-method (keyword (st/lower-case method))) | |
request)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment