Fork me on GitHub
#pedestal
<
2022-04-16
>
sb09:04:55

I would like to use “X-HTTP-Method-Override” in Pedestal. I see that is needed an extra setup. I found one at RING case

(defn wrap-method-override
  "Ring middleware for method overriding (X-HTTP-Method-Override)"
  [handler]
  (fn [req]
    (let [x-http-method (get (-> req :headers) "x-http-method-override" "")]
      (if (contains? #{"delete" "put"} (string/lower-case x-http-method))
        (handler (if x-http-method (assoc req :request-method (keyword (string/lower-case x-http-method))) req))
        (handler req)))))
[from ithaka]. Example request
(ajax-request
  {:uri             "/api/post-get" ;; both exist here, get and post
   :method          :post
   :headers         {"X-HTTP-Method-Override" "GET"}
   :params          {:q  "something here"}
   :handler         (fn [data]
                      (js/console.log "success2 " data))
   :error-handler   (fn [data]
                      (js/console.log "error " data))
   :format          (ajax.json/json-request-format)
   :response-format (ajax.json/json-response-format)})
when I call, I see in the logs POST request, which is normally np.. because I can send back data in this way. Just I really want to understand why I can’t mod the method. I use Jetty + Pedestal. Any idea, maybe I need to write an interceptor or I need to add at Jetty side something (like Ring)? Maybe at
:io.pedestal.http.jetty/http-configuration 
side (container options)?

sb10:04:54

Ofc, I can route POST to GET on server side, just my question is, is that possible in real change/ mod the method or not.

camdez17:04:01

@U2T2ZEVPC I’m not deeply knowledgeable here, but the original request map uses :method whereas the middleware assoces :request-method. Possibly just that?

👍 1
sb02:04:51

Thanks I check it!

sb09:04:58

Ps. I tested with js/fetch too, same result.