Skip to content

Commit

Permalink
Merge pull request #46 from josephwilk/development
Browse files Browse the repository at this point in the history
Add remove-params-on-redirect option
  • Loading branch information
neotyk committed Jan 29, 2013
2 parents 018633b + 7ea9375 commit 6f58d58
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/clj/http/async/client.clj
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down
12 changes: 12 additions & 0 deletions test/http/async/client/test.clj
Expand Up @@ -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"))))
Expand Down

0 comments on commit 6f58d58

Please sign in to comment.