|
Play Framework/Scala example source code file (HttpSpec.scala)
The HttpSpec.scala Play Framework example source code
package play.api.mvc
import play.api.http.HeaderNames
import play.api.test.FakeRequest
object HttpSpec extends org.specs2.mutable.Specification {
"HTTP" title
"Absolute URL" should {
val req = FakeRequest().withHeaders(HeaderNames.HOST -> "playframework.com")
"have HTTP scheme" in {
(Call("GET", "/playframework").absoluteURL()(req).
aka("absolute URL 1") must_== "http://playframework.com/playframework").
and(Call("GET", "/playframework").absoluteURL(false)(req).
aka("absolute URL 2") must_== (
"http://playframework.com/playframework"))
}
"have HTTPS scheme" in {
(Call("GET", "/playframework").absoluteURL()(req.copy(secure = true)).
aka("absolute URL 1") must_== (
"https://playframework.com/playframework")) and (
Call("GET", "/playframework").absoluteURL(true)(req).
aka("absolute URL 2") must_== (
"https://playframework.com/playframework"))
}
}
"Web socket URL" should {
val req = FakeRequest().withHeaders(
HeaderNames.HOST -> "playframework.com")
"have WS scheme" in {
(Call("GET", "/playframework").webSocketURL()(req).
aka("absolute URL 1") must_== "ws://playframework.com/playframework").
and(Call("GET", "/playframework").webSocketURL(false)(req).
aka("absolute URL 2") must_== (
"ws://playframework.com/playframework"))
}
"have WSS scheme" in {
(Call("GET", "/playframework").webSocketURL()(req.copy(secure = true)).
aka("absolute URL 1") must_== (
"wss://playframework.com/playframework")) and (
Call("GET", "/playframework").webSocketURL(true)(req).
aka("absolute URL 2") must_== (
"wss://playframework.com/playframework"))
}
}
"RequestHeader" should {
"parse quoted and unquoted charset" in {
FakeRequest().withHeaders(
HeaderNames.CONTENT_TYPE -> """text/xml; charset="utf-8"""").
charset aka "request charset" must beSome("utf-8")
}
"parse quoted and unquoted charset" in {
FakeRequest().withHeaders(
HeaderNames.CONTENT_TYPE -> "text/xml; charset=utf-8").
charset aka "request charset" must beSome("utf-8")
}
}
}
Other Play Framework source code examplesHere is a short list of links related to this Play Framework HttpSpec.scala source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.