Skip to content

Commit e2406ff

Browse files
committed
add support for the :patch HTTP method
also fixes tests for the strange HTTP methods no one actually uses
1 parent 91d5146 commit e2406ff

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Require it in your application:
4444
```
4545

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

5050
```clojure
5151
(client/get "http://google.com")

changelog.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
** 2012-04-27
140140
- merged https://github.com/dakrone/clj-http/pull/68 to support
141141
additional options/delete/copy/move HTTP methods
142+
- add support for the :patch method type
142143
** Release 0.4.0
143144
** 2012-04-22
144145
- merged https://github.com/dakrone/clj-http/pull/66 to add support

src/clj_http/client.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,12 @@
472472
(check-url! url)
473473
(request (merge req {:method :move :url url})))
474474

475+
(defn patch
476+
"Like #'request, but sets the :method and :url as appropriate."
477+
[url & [req]]
478+
(check-url! url)
479+
(request (merge req {:method :patch :url url})))
480+
475481
(defmacro with-connection-pool
476482
"Macro to execute the body using a connection manager. Creates a
477483
ThreadSafeClientConnectionManager to use for all requests within the body of

src/clj_http/core.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
(def proxy-get-with-body (make-proxy-method-with-body :get))
6262
(def proxy-copy-with-body (make-proxy-method-with-body :copy))
6363
(def proxy-move-with-body (make-proxy-method-with-body :move))
64+
(def proxy-patch-with-body (make-proxy-method-with-body :patch))
6465

6566
(def ^SSLSocketFactory insecure-socket-factory
6667
(doto (SSLSocketFactory. (reify TrustStrategy
@@ -203,6 +204,7 @@
203204
:delete (proxy-delete-with-body http-url)
204205
:copy (proxy-copy-with-body http-url)
205206
:move (proxy-move-with-body http-url)
207+
:patch (proxy-patch-with-body http-url)
206208
(throw (IllegalArgumentException.
207209
(str "Invalid request method " request-method))))]
208210
(when (and content-type character-encoding)

test/clj_http/test/core.clj

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@
4242
[:get "/get-with-body"]
4343
{:status 200 :body (:body req)}
4444
[:options "/options"]
45-
{:status 200 :body req}
46-
[:options "/copy"]
47-
{:status 200 :body req}
48-
[:options "/move"]
49-
{:status 200 :body req}))
45+
{:status 200 :body "options"}
46+
[:copy "/copy"]
47+
{:status 200 :body "copy"}
48+
[:move "/move"]
49+
{:status 200 :body "move"}
50+
[:patch "/patch"]
51+
{:status 200 :body "patch"}))
5052

5153
(defn run-server
5254
[]
@@ -258,10 +260,12 @@
258260
;; super-basic test for methods that aren't used that often
259261
(deftest ^{:integration true} t-copy-options-move
260262
(run-server)
261-
(let [resp1 (client/get "http://localhost:18080/options")
262-
resp2 (client/get "http://localhost:18080/move")
263-
resp3 (client/get "http://localhost:18080/copy")]
264-
(is (= #{200} (set (map :status [resp1 resp2 resp3]))))
265-
(is (= :options (:method resp1)))
266-
(is (= :move (:method resp2)))
267-
(is (= :copy (:method resp3)))))
263+
(let [resp1 (client/options "http://localhost:18080/options")
264+
resp2 (client/move "http://localhost:18080/move")
265+
resp3 (client/copy "http://localhost:18080/copy")
266+
resp4 (client/patch "http://localhost:18080/patch")]
267+
(is (= #{200} (set (map :status [resp1 resp2 resp3 resp4]))))
268+
(is (= "options" (:body resp1)))
269+
(is (= "move" (:body resp2)))
270+
(is (= "copy" (:body resp3)))
271+
(is (= "patch" (:body resp4)))))

0 commit comments

Comments
 (0)