2014-08-06 17:49:48 +00:00
|
|
|
(ns puppetlabs.http.client.test-common
|
|
|
|
(:require [ring.middleware.params :as ring-params]
|
|
|
|
[puppetlabs.trapperkeeper.core :as tk]))
|
|
|
|
|
|
|
|
(defn query-params-test
|
|
|
|
[req]
|
|
|
|
{:status 200
|
2014-08-07 17:36:03 +00:00
|
|
|
:body (str (:query-params req))})
|
2014-08-06 17:49:48 +00:00
|
|
|
|
|
|
|
(def app-wrapped
|
|
|
|
(ring-params/wrap-params query-params-test))
|
|
|
|
|
|
|
|
(tk/defservice test-params-web-service
|
|
|
|
[[:WebserverService add-ring-handler]]
|
|
|
|
(init [this context]
|
|
|
|
(add-ring-handler app-wrapped "/params")
|
|
|
|
context))
|
|
|
|
|
2014-08-07 17:36:03 +00:00
|
|
|
(def queryparams {"foo" "bar"
|
|
|
|
"baz" "lux"})
|
2014-08-06 21:23:56 +00:00
|
|
|
|
2014-08-06 21:33:26 +00:00
|
|
|
(def query-options {:method :get
|
|
|
|
:url "http://localhost:8080/params/"
|
2014-08-06 21:23:56 +00:00
|
|
|
:query-params queryparams
|
2014-08-25 18:15:22 +00:00
|
|
|
:as :text})
|
|
|
|
|
|
|
|
(defn redirect-test-handler
|
|
|
|
[req]
|
|
|
|
(condp = (:uri req)
|
|
|
|
"/hello/world" {:status 200 :body "Hello, World!"}
|
2014-10-18 02:12:43 +00:00
|
|
|
"/hello" {:status 302
|
2014-08-25 18:15:22 +00:00
|
|
|
:headers {"Location" "/hello/world"}
|
|
|
|
:body ""}
|
|
|
|
{:status 404 :body "D'oh"}))
|
|
|
|
|
|
|
|
(tk/defservice redirect-web-service
|
|
|
|
[[:WebserverService add-ring-handler]]
|
|
|
|
(init [this context]
|
|
|
|
(add-ring-handler redirect-test-handler "/hello")
|
|
|
|
context))
|