Skip to content

Commit

Permalink
Merge branch 'master' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
neotyk committed Apr 7, 2011
2 parents 64b6c1b + fec1933 commit ade1f72
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
9 changes: 5 additions & 4 deletions src/clj/http/async/client.clj
Expand Up @@ -44,10 +44,11 @@
:password - (optional) password to use for proxy authentication,
has to be provided with :user
- :auth :: map with authentication to be used
:type - either :basic or :digest
:user - user name to be used
:password - password to be used
:realm - realm name to authenticate in
:type - either :basic or :digest
:user - user name to be used
:password - password to be used
:realm - realm name to authenticate in
:preemptive - assume authentication is required
- :request-timeout :: request timeout in ms
- :user-agent :: User-Agent branding string
- :async-connect :: Execute connect asynchronously
Expand Down
11 changes: 6 additions & 5 deletions src/clj/http/async/client/request.clj
Expand Up @@ -35,7 +35,7 @@
ByteArrayInputStream
ByteArrayOutputStream)))

(def *user-agent* "http.async.client/0.2.1-dev")
(def *user-agent* "http.async.client/0.2.2")

(def *client*
(AsyncHttpClient.
Expand Down Expand Up @@ -123,10 +123,11 @@
:password - (optional) password to use for proxy authentication,
has to be provided with :user
:auth - map with authentication to be used
:type - either :basic or :digest
:user - user name to be used
:password - password to be used
:realm - realm name to authenticate in
:type - either :basic or :digest
:user - user name to be used
:password - password to be used
:realm - realm name to authenticate in
:preemptive - assume authentication is required
:timeout - request timeout in ms"
{:tag Request}
[method #^String url & {:keys [headers
Expand Down
10 changes: 4 additions & 6 deletions src/clj/http/async/client/util.clj
Expand Up @@ -123,12 +123,8 @@

(defn set-realm
"Sets realm on builder."
[{type :type
user :user
password :password
realm :realm
:or {:type :basic}}
b]
[{:keys [type user password realm preemptive]
:or {:type :basic}} b]
(let [rbld (Realm$RealmBuilder.)]
(when (nil? user)
(if (nil? password)
Expand All @@ -141,6 +137,8 @@
"For DIGEST authentication realm is required")))
(.setRealmName rbld realm)
(.setScheme rbld Realm$AuthScheme/DIGEST))
(when (not (nil? preemptive))
(.setUsePreemptiveAuth rbld preemptive))
(doto rbld
(.setPrincipal user)
(.setPassword password))
Expand Down
19 changes: 19 additions & 0 deletions test/http/async/client/test.clj
Expand Up @@ -103,6 +103,12 @@
(if (= auth "Basic YmVhc3RpZTpib3lz")
200
401)))
"/preemptive-auth" (let [auth (.getHeader hReq "Authorization")]
(.setStatus
hResp
(if (= auth "Basic YmVhc3RpZTpib3lz")
200
401)))
"/timeout" (Thread/sleep 2000)
"/empty" (.setHeader hResp "Nothing" "Yep")
(doseq [n (enumeration-seq (.getParameterNames hReq))]
Expand Down Expand Up @@ -475,6 +481,19 @@
:password "boys"})))
200)))

(deftest preemptive-authentication
(is (=
(:code (status (GET "http://localhost:8123/preemptive-auth"
:auth {:user "beastie"
:password "boys"})))
401))
(is (=
(:code (status (GET "http://localhost:8123/preemptive-auth"
:auth {:user "beastie"
:password "boys"
:preemptive true})))
200)))

(deftest canceling-request
(let [resp (GET "http://localhost:8123/")]
(is (false? (cancelled? resp)))
Expand Down

0 comments on commit ade1f72

Please sign in to comment.