Skip to content

Commit 6687f2a

Browse files
Merge pull request #207 from dispatch/1.0/realm-with-scheme
[1.0] Allow to set scheme in as keyword
2 parents f575941 + 016ddea commit 6687f2a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

core/src/main/scala/requests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ trait ParamVerbs extends RequestVerbs {
271271
}
272272

273273
trait AuthVerbs extends RequestVerbs {
274-
def as(user: String, password: String): Req =
275-
this.as(new Realm.Builder(user, password).build())
274+
def as(user: String, password: String, scheme: AuthScheme): Req =
275+
this.as(new Realm.Builder(user, password).setScheme(scheme).build())
276276

277277
/** Basic auth, use with care. */
278278
def as_!(user: String, password: String): Req =

core/src/test/scala/basic.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package dispatch.spec
22

33
import java.nio.charset.Charset
44

5+
import org.asynchttpclient.Realm
6+
import org.asynchttpclient.Realm.AuthScheme
57
import org.scalacheck._
8+
import org.scalacheck.Prop._
69

710
object BasicSpecification
811
extends Properties("Basic")
@@ -166,4 +169,19 @@ with DispatchCleanup {
166169
req.toRequest.getUrl ?= "http://127.0.0.1:%d/?%s".format(port, expectedParams.mkString("&"))
167170
}
168171
}
172+
173+
property("Building a Realm without a scheme should throw NPE") = {
174+
forAll(Gen.zip(Gen.alphaNumStr, Gen.alphaNumStr)) { case (user, password) =>
175+
throws(classOf[NullPointerException])(new Realm.Builder(user, password).build())
176+
}
177+
}
178+
179+
property("Build a Realm using as") = {
180+
forAll(Gen.zip(Gen.alphaNumStr, Gen.alphaNumStr, Gen.oneOf(AuthScheme.values()))) { case (user, password, scheme) =>
181+
val realm = localhost.as(user, password, scheme).toRequest.getRealm
182+
realm.getScheme ?= scheme
183+
realm.getPrincipal ?= user
184+
realm.getPassword ?= password
185+
}
186+
}
169187
}

0 commit comments

Comments
 (0)