Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support for encoded slashes, for issue #23

  • Loading branch information...
commit 456d87bb529e77726dbebdf145b00381c88cdfba 1 parent 3e6c408
@n8han n8han authored
View
3  core/src/main/scala/package.scala
@@ -12,9 +12,6 @@ package object dispatch {
implicit def implyRequestHandlerTuple(builder: Req) =
new RequestHandlerTupleBuilder(builder)
- implicit def implyRawURI(uri: Uri) =
- new RawUri(uri)
-
implicit def implyRunnable[U](f: () => U) = new java.lang.Runnable {
def run() { f() }
}
View
8 core/src/main/scala/requests.scala
@@ -45,16 +45,16 @@ trait MethodVerbs extends RequestVerbs {
trait UrlVerbs extends RequestVerbs {
def url = subject.build.getUrl
def / (segment: String) = {
- val uri = new Uri(url)
+ val uri = RawUri(url)
val encodedSegment = UriEncode.path(segment)
- val rawPath = uri.getRawPath match {
+ val rawPath = uri.path.orElse(Some("/")).map {
case u if u.endsWith("/") => u + encodedSegment
case u => u + "/" + encodedSegment
}
- subject.setUrl(uri.copy(path=Some(rawPath)).toString)
+ subject.setUrl(uri.copy(path=rawPath).toString)
}
def secure = {
- subject.setUrl(new Uri(url).copy(scheme=Some("https")).toString)
+ subject.setUrl(RawUri(url).copy(scheme=Some("https")).toString)
}
}
View
58 core/src/main/scala/uri.scala
@@ -1,5 +1,42 @@
package dispatch
+/** URI representation with raw parts, so */
+case class RawUri(
+ scheme: Option[String],
+ userInfo: Option[String],
+ host: Option[String],
+ port: Option[Int],
+ path: Option[String],
+ query: Option[String],
+ fragment: Option[String]
+) {
+ def toUri = new Uri(
+ (scheme.map { _ + ":" } ::
+ Some("//") ::
+ userInfo.map { _ + "@" } ::
+ host ::
+ port.map { ":" + _ } ::
+ path ::
+ query.map { "?" + _ } ::
+ fragment.map { "#" + _ } ::
+ Nil
+ ).flatten.mkString)
+ override def toString = toUri.toASCIIString
+}
+
+object RawUri {
+ def apply(str: String): RawUri = RawUri(new Uri(str))
+ def apply(subject: Uri): RawUri = RawUri(
+ scheme = Option(subject.getScheme),
+ userInfo = Option(subject.getRawUserInfo),
+ host = Option(subject.getHost),
+ port = Some(subject.getPort).filter( _ != -1),
+ path = Option(subject.getRawPath),
+ query = Option(subject.getRawQuery),
+ fragment = Option(subject.getRawFragment)
+ )
+}
+
object UriEncode {
// uri character sets
def alpha = lowalpha ++ upalpha
@@ -24,24 +61,3 @@ object UriEncode {
}).mkString
}
}
-
-class RawUri(subject: Uri) {
- def copy(
- scheme: Option[String] = Option(subject.getScheme),
- userInfo: Option[String] = Option(subject.getRawUserInfo),
- host: Option[String] = Option(subject.getHost),
- port: Option[Int] = Some(subject.getPort).filter( _ != -1),
- path: Option[String] = Option(subject.getRawPath),
- query: Option[String] = Option(subject.getRawQuery),
- fragment: Option[String] = Option(subject.getRawFragment)
- ) =
- (scheme.map { _ + ":" } ::
- userInfo.map { _ + "@" } ::
- host ::
- port.map { ":" + _ } ::
- path ::
- query.map { "?" + _ } ::
- fragment.map { "#" + _ } ::
- Nil
- ).flatten.mkString
-}

0 comments on commit 456d87b

Please sign in to comment.
Something went wrong with that request. Please try again.