Permalink
Browse files

Merge branch 'master' of github.com:dispatch/reboot

  • Loading branch information...
2 parents 53bf687 + 5a3654d commit ec8684ea715b1359b13a12d9be6199d823ca9247 @n8han n8han committed Aug 30, 2012
Showing with 44 additions and 10 deletions.
  1. +9 −1 README.markdown
  2. +8 −4 core/src/main/scala/requests.scala
  3. +27 −5 core/src/test/scala/basic.scala
View
@@ -1,9 +1,17 @@
Dispatch Reboot
---------------
-Dispatch reboot is a rewrite of the [Dispatch][dispatch] library for
+Dispatch reboot is a rewrite of the Dispatch library for
HTTP interaction in Scala, using [sonatype/async-http-client][async]
as its underlying transport. For more info, see the
[Dispatch documentation site][docs].
[docs]: http://dispatch.databinder.net/Dispatch.html
+[async]: https://github.com/sonatype/async-http-client
+
+### Mailing List
+
+There's a [mailing list for Dispatch][mail]. Please mail the list **before opening
+github issues** for problems that are not obvious, reproducable bugs.
+
+[mail]: https://groups.google.com/forum/?fromgroups#!forum/dispatch-scala
@@ -1,6 +1,7 @@
package dispatch
import com.ning.http.client.RequestBuilder
+import java.net.{URLDecoder, URLEncoder}
class DefaultRequestVerbs(val subject: RequestBuilder)
extends MethodVerbs with UrlVerbs with ParamVerbs with AuthVerbs
@@ -34,12 +35,15 @@ trait MethodVerbs extends RequestVerbs {
}
trait UrlVerbs extends RequestVerbs {
+ private val encode = URLEncoder.encode(_: String, "utf-8")
import java.net.URI
def url = subject.build.getUrl // unfortunate
- def / (path: String) = subject.setUrl(url match {
- case u if u.endsWith("/") => u + path
- case u => u + "/" + path
- })
+ def / (path: String) = {
+ subject.setUrl(url match {
+ case u if u.endsWith("/") => u + encode(path)
+ case u => u + "/" + encode(path)
+ })
+ }
def secure = {
val uri = URI.create(url)
subject.setUrl(new URI(
@@ -5,7 +5,8 @@ import org.scalacheck._
object BasicSpecification
extends Properties("Basic")
with unfiltered.spec.ServerCleanup {
- import Prop.forAll
+ import java.net.{URLEncoder,URLDecoder}
+ import Prop._
val server = {
import unfiltered.netty
@@ -15,38 +16,59 @@ with unfiltered.spec.ServerCleanup {
netty.Http.anylocal.handler(netty.cycle.Planify {
case req @ Path("/echo") & Params(Echo(echo)) =>
PlainTextContent ~> ResponseString(req.method + echo)
+ case req @ Path(Seg("echopath" :: echo :: _)) =>
+ PlainTextContent ~> ResponseString(req.method + URLDecoder.decode(echo, "utf-8"))
+ case req @ Path(Seg("echopath" :: Nil)) =>
+ PlainTextContent ~> ResponseString(req.method)
}).start()
}
import dispatch._
def localhost = host("127.0.0.1", server.port)
+ // a shim until we can update scalacheck to a version that non-alpha strings that don't break Java
+ val syms = "&#$@%"
+
property("POST and handle") = forAll(Gen.alphaStr) { (sample: String) =>
val res = Http(
localhost / "echo" << Map("echo" -> sample) > as.String
)
- res() == ("POST" + sample)
+ res() =? ("POST" + sample)
}
property("GET and handle") = forAll(Gen.alphaStr) { (sample: String) =>
val res = Http(
localhost / "echo" <<? Map("echo" -> sample) > as.String
)
- res() == ("GET" + sample)
+ res() =? ("GET" + sample)
}
property("GET and get response") = forAll(Gen.alphaStr) { (sample: String) =>
val res = Http(
localhost / "echo" <<? Map("echo" -> sample)
)
- res().getResponseBody == ("GET" + sample)
+ res().getResponseBody =? ("GET" + sample)
+ }
+
+ property("GET with encoded path") = forAll(Gen.alphaStr) { (sample: String) =>
+ // (second sample in request path is ignored)
+ val res = Http(
+ localhost / "echopath" / (sample + syms) / sample OK as.String
+ )
+ ("GET" + sample + syms) =? res()
+ }
+
+ property("GET with encoded path as url") = forAll(Gen.alphaStr) { (sample: String) =>
+ val requesturl = "http://127.0.0.1:%d/echopath/%s".format(server.port, URLEncoder.encode(sample + syms, "utf-8"))
+ val res = Http(url(requesturl) / sample OK as.String)
+ res() == ("GET" + sample + syms)
}
property("OPTIONS and handle") = forAll(Gen.alphaStr) { (sample: String) =>
val res = Http(
localhost.OPTIONS / "echo" <<? Map("echo" -> sample) > as.String
)
- res() == ("OPTIONS" + sample)
+ res() =? ("OPTIONS" + sample)
}
}

0 comments on commit ec8684e

Please sign in to comment.