Skip to content

Commit b03278f

Browse files
committed
Merge remote-tracking branch 'cemerick/master'
2 parents 36b6243 + 6a879b9 commit b03278f

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

Readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ Require it in your application:
4343
(:require [clj-http.client :as client]))
4444
```
4545

46-
The client supports simple `get`, `head`, `put`, `post`, and `delete`
47-
requests. Responses are returned as Ring-style response maps:
46+
The client supports simple `get`, `head`, `put`, `post`, `delete`,
47+
`copy`, `move`, and `options` requests. Responses are returned as
48+
Ring-style response maps:
4849

4950
```clojure
5051
(client/get "http://google.com")

src/clj_http/core.clj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
(org.apache.http.client HttpClient HttpRequestRetryHandler)
1717
(org.apache.http.client.methods HttpGet HttpHead HttpPut
1818
HttpPost HttpDelete
19+
HttpOptions
1920
HttpEntityEnclosingRequestBase)
2021
(org.apache.http.client.params CookiePolicy ClientPNames)
2122
(org.apache.http.conn ClientConnectionManager)
@@ -59,6 +60,8 @@
5960

6061
(def proxy-delete-with-body (make-proxy-method-with-body :delete))
6162
(def proxy-get-with-body (make-proxy-method-with-body :get))
63+
(def proxy-copy-with-body (make-proxy-method-with-body :copy))
64+
(def proxy-move-with-body (make-proxy-method-with-body :move))
6265

6366
(def ^SSLSocketFactory insecure-socket-factory
6467
(doto (SSLSocketFactory. (reify TrustStrategy
@@ -193,11 +196,16 @@
193196
req (assoc req :http-url http-url)
194197
#^HttpRequest
195198
http-req (case request-method
196-
:get (proxy-get-with-body http-url)
197-
:head (HttpHead. http-url)
198-
:put (HttpPut. http-url)
199-
:post (HttpPost. http-url)
200-
:delete (proxy-delete-with-body http-url))]
199+
:get (proxy-get-with-body http-url)
200+
:head (HttpHead. http-url)
201+
:put (HttpPut. http-url)
202+
:post (HttpPost. http-url)
203+
:options (HttpOptions. http-url)
204+
:delete (proxy-delete-with-body http-url)
205+
:copy (proxy-copy-with-body http-url)
206+
:move (proxy-move-with-body http-url)
207+
(throw (IllegalArgumentException.
208+
(str "Invalid request method " request-method))))]
201209
(when (and content-type character-encoding)
202210
(.addHeader http-req "Content-Type"
203211
(str content-type "; charset=" character-encoding)))

test/clj_http/test/core.clj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@
192192
body (slurp stream)]
193193
(is (= "get" body))))
194194

195+
(deftest throw-on-invalid-body
196+
(is (thrown-with-msg? IllegalArgumentException #"Invalid request method :bad"
197+
(client/request {:method :bad :url "http://example.org"}))))
198+
195199
(deftest ^{:integration true} throw-on-too-many-redirects
196200
(run-server)
197201
(let [resp (client/get "http://localhost:18080/redirect"

0 commit comments

Comments
 (0)