Permalink
Browse files

Add remove-params-on-redirect option

  • Loading branch information...
1 parent 2f7d8e0 commit 7ea93755f155ef1e0b0380c3098957ca37b65a7d @josephwilk josephwilk committed Jan 28, 2013
Showing with 15 additions and 0 deletions.
  1. +3 −0 src/clj/http/async/client.clj
  2. +12 −0 test/http/async/client/test.clj
@@ -38,6 +38,7 @@
- :compression-enabled :: enable HTTP compression
- :connection-timeout :: connections timeout in ms
- :follow-redirects :: enable following HTTP redirects
+ - :remove-params-on-redirect :: query parameters removed when a redirect occurs
- :idle-in-pool-timeout :: idle connection in pool timeout in ms
- :keep-alive :: enable HTTP keep alive, enabled by default
- :max-conns-per-host :: max number of polled connections per host
@@ -67,6 +68,7 @@
[& {:keys [compression-enabled
connection-timeout
follow-redirects
+ remove-params-on-redirect
idle-in-pool-timeout
keep-alive
max-conns-per-host
@@ -84,6 +86,7 @@
(let [b (AsyncHttpClientConfig$Builder.)]
(when-not (nil? compression-enabled) (.setCompressionEnabled b compression-enabled))
(when connection-timeout (.setConnectionTimeoutInMs b connection-timeout))
+ (when-not (nil? remove-params-on-redirect) (.setRemoveQueryParamsOnRedirect b remove-params-on-redirect))
(when-not (nil? follow-redirects) (.setFollowRedirects b follow-redirects))
(when idle-in-pool-timeout (.setIdleConnectionInPoolTimeoutInMs b idle-in-pool-timeout))
(when-not (nil? keep-alive) (.setAllowPoolingConnection b keep-alive))
@@ -639,6 +639,18 @@
(is (true? (redirect? resp)))
(is (= "http://localhost:8123/here" (location resp)))))
+(deftest following-redirect-with-params
+ (with-open [client (create-client :remove-params-on-redirect false :follow-redirects true)]
+ (let [resp (GET client "http://localhost:8123/redirect" :query {:token "1234"})
+ headers (headers resp)]
+ (are [x y] (= (x headers) (str y)) :token "1234"))))
+
+(deftest following-redirect-without-params
+ (with-open [client (create-client :remove-params-on-redirect true :follow-redirects true)]
+ (let [resp (GET client "http://localhost:8123/redirect" :query {:token "1234"})
+ headers (headers resp)]
+ (is (false? (contains? headers :token))))))
+
(deftest content-type-fn
(let [resp (GET *client* "http://localhost:8123/body")]
(is (.startsWith (content-type resp) "text/plain"))))

0 comments on commit 7ea9375

Please sign in to comment.