Permalink
Browse files

Add queryString parser. (#42)

* Add queryString parser.

* Update Request.scala

* Update Request.scala

* Update Request.scala
  • Loading branch information...
guillaumebort committed Oct 24, 2017
1 parent 78a192c commit 254108d46a27afc88ae97992f3e480d48b8ac6f7
Showing with 21 additions and 6 deletions.
  1. +3 −3 README.md
  2. +1 −1 build.sbt
  3. +8 −2 core/src/main/scala/Request.scala
  4. +9 −0 core/src/test/scala/UrlTests.scala
View
@@ -35,12 +35,12 @@ HTTP/2 is supported on both server and client side. If SSL is enabled, the proto
The library is cross-built for __Scala 2.11__ and __Scala 2.12__.
The core module to use is `"com.criteo.lolhttp" %% "lolhttp" % "0.7.3"`.
The core module to use is `"com.criteo.lolhttp" %% "lolhttp" % "0.7.4"`.
There are also 2 optional companion libraries:
- `"com.criteo.lolhttp" %% "loljson" % "0.7.3"`, provides integration with the [circe](https://circe.github.io/circe/) JSON library.
- `"com.criteo.lolhttp" %% "lolhtml" % "0.7.3"`, provides minimal HTML templating.
- `"com.criteo.lolhttp" %% "loljson" % "0.7.4"`, provides integration with the [circe](https://circe.github.io/circe/) JSON library.
- `"com.criteo.lolhttp" %% "lolhtml" % "0.7.4"`, provides minimal HTML templating.
## Documentation
View
@@ -1,4 +1,4 @@
val VERSION = "0.7.3"
val VERSION = "0.7.4"
lazy val commonSettings = Seq(
organization := "com.criteo.lolhttp",
@@ -34,10 +34,16 @@ case class Request(
}
/** The path part of the URL (ie. without the queryString). */
lazy val path = p
lazy val path: String = p
/** The queryString part of the URL. */
lazy val queryString = qs
lazy val queryString: Option[String] = qs
/** The queryString parsed as a sequence of key=value parameters. */
lazy val parsedQueryString: List[(String,String)] = qs.map(internal.Url.parseQueryString).getOrElse(Nil)
/** The queryString parameters. Duplicated parameters are ignored, only the first value is available. */
lazy val queryStringParameters: Map[String,String] = parsedQueryString.toMap
/** Set the content of this request.
* @param content the content to use for this request.
@@ -39,4 +39,13 @@ class UrlsTests extends Tests {
"/?name=jean-claude" match { case url"/?name=$first-$last" => (first,last) should be ("jean" -> "claude") }
}
test("QueryString in request") {
Get("/").parsedQueryString should be (Nil)
Get("/").queryStringParameters should be (Map.empty)
Get("/?sort=asc&page=2").parsedQueryString should be (List("sort" -> "asc", "page" -> "2"))
Get("/?sort=asc&page=2").queryStringParameters should be (Map("sort" -> "asc", "page" -> "2"))
Get("/?sort=asc&page=2&sort=desc").parsedQueryString should be (List("sort" -> "asc", "page" -> "2", "sort" -> "desc"))
Get("/?sort=asc&page=2").queryStringParameters should be (Map("sort" -> "asc", "page" -> "2"))
}
}

0 comments on commit 254108d

Please sign in to comment.