Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
54 lines (44 sloc) 1.88 KB
(ns clojure-http.test.client
(:use [clojure-http.client] :reload)
(:use [clojure.test]
[ :only [reader writer]]
[clojure.contrib.str-utils :only [str-join]]
[clojure.contrib.server-socket :only [create-server]]))
(def test-port 8239)
(defn response-headers
(reduce #(conj %1 (str-join ":" %2))
'("HTTP/1.1 200 OK"
"Server: clojure-http-test-client"
"Content-Type: text/plain")
(defn echo-http-response [ins outs]
(with-open [in (reader ins), out (writer outs)]
(binding [*in* in, *out* out]
(println (str-join "\n" (response-headers {})))
(loop [input (read-line)]
;; TODO: this conditional ignores request bodies
(when (not= "" input)
(println input)
(recur (read-line)))))))
;; (.close (:server-socket server))
;; (def server (create-server test-port echo-http-response))
(defonce server (create-server test-port echo-http-response))
(deftest simple-get
(let [response (request (str "http://localhost:" test-port))]
(is (= "OK" (:msg response)))
(is (= 200 (:code response)))
(is (= "GET / HTTP/1.1" (first (:body-seq response))))))
(deftest custom-header-get
(let [response (request (str "http://localhost:" test-port)
:get {"How-Awesome" "very"})]
(is (some #{"How-Awesome: very"} (:body-seq response)))))
(deftest case-insensitive-headers
(let [response (request (str "http://localhost:" test-port))]
(is (= "text/plain" ((:get-header response) "content-type")))))
;; need echo response to work with body before this will work.
;; (deftest request-body
;; (let [response (request (str "http://localhost:" test-port)
;; :get {} {} {"hey" "düde"})]
;; (is (some #{"o=hai+dere&hey=d%C3%B6od"} (:body-seq response)))))
Something went wrong with that request. Please try again.