Update to a working version of Scalariform
This commit is contained in:
parent
cae070bd93
commit
c66ce62d63
616 changed files with 5966 additions and 5436 deletions
|
|
@ -178,7 +178,8 @@ class HttpServerExampleSpec extends WordSpec with Matchers
|
|||
|
||||
val requestHandler: HttpRequest => HttpResponse = {
|
||||
case HttpRequest(GET, Uri.Path("/"), _, _, _) =>
|
||||
HttpResponse(entity = HttpEntity(ContentTypes.`text/html(UTF-8)`,
|
||||
HttpResponse(entity = HttpEntity(
|
||||
ContentTypes.`text/html(UTF-8)`,
|
||||
"<html><body>Hello world!</body></html>"))
|
||||
|
||||
case HttpRequest(GET, Uri.Path("/ping"), _, _, _) =>
|
||||
|
|
@ -218,7 +219,8 @@ class HttpServerExampleSpec extends WordSpec with Matchers
|
|||
|
||||
val requestHandler: HttpRequest => HttpResponse = {
|
||||
case HttpRequest(GET, Uri.Path("/"), _, _, _) =>
|
||||
HttpResponse(entity = HttpEntity(ContentTypes.`text/html(UTF-8)`,
|
||||
HttpResponse(entity = HttpEntity(
|
||||
ContentTypes.`text/html(UTF-8)`,
|
||||
"<html><body>Hello world!</body></html>"))
|
||||
|
||||
case HttpRequest(GET, Uri.Path("/ping"), _, _, _) =>
|
||||
|
|
@ -236,7 +238,7 @@ class HttpServerExampleSpec extends WordSpec with Matchers
|
|||
StdIn.readLine() // let it run until user presses return
|
||||
bindingFuture
|
||||
.flatMap(_.unbind()) // trigger unbinding from the port
|
||||
.onComplete(_ ⇒ system.terminate()) // and shutdown when done
|
||||
.onComplete(_ => system.terminate()) // and shutdown when done
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -278,7 +280,7 @@ class HttpServerExampleSpec extends WordSpec with Matchers
|
|||
StdIn.readLine() // let it run until user presses return
|
||||
bindingFuture
|
||||
.flatMap(_.unbind()) // trigger unbinding from the port
|
||||
.onComplete(_ ⇒ system.terminate()) // and shutdown when done
|
||||
.onComplete(_ => system.terminate()) // and shutdown when done
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -310,7 +312,7 @@ class HttpServerExampleSpec extends WordSpec with Matchers
|
|||
StdIn.readLine() // let it run until user presses return
|
||||
bindingFuture
|
||||
.flatMap(_.unbind()) // trigger unbinding from the port
|
||||
.onComplete(_ ⇒ system.terminate()) // and shutdown when done
|
||||
.onComplete(_ => system.terminate()) // and shutdown when done
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -466,7 +468,7 @@ class HttpServerExampleSpec extends WordSpec with Matchers
|
|||
StdIn.readLine() // let it run until user presses return
|
||||
bindingFuture
|
||||
.flatMap(_.unbind()) // trigger unbinding from the port
|
||||
.onComplete(_ ⇒ system.terminate()) // and shutdown when done
|
||||
.onComplete(_ => system.terminate()) // and shutdown when done
|
||||
}
|
||||
}
|
||||
//#stream-random-numbers
|
||||
|
|
@ -533,7 +535,7 @@ class HttpServerExampleSpec extends WordSpec with Matchers
|
|||
StdIn.readLine() // let it run until user presses return
|
||||
bindingFuture
|
||||
.flatMap(_.unbind()) // trigger unbinding from the port
|
||||
.onComplete(_ ⇒ system.terminate()) // and shutdown when done
|
||||
.onComplete(_ => system.terminate()) // and shutdown when done
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ object MyRejectionHandler {
|
|||
.handle { case MissingCookieRejection(cookieName) =>
|
||||
complete(HttpResponse(BadRequest, entity = "No cookies, no service!!!"))
|
||||
}
|
||||
.handle { case AuthorizationFailedRejection ⇒
|
||||
.handle { case AuthorizationFailedRejection =>
|
||||
complete((Forbidden, "You're out of your depth!"))
|
||||
}
|
||||
.handle { case ValidationRejection(msg, _) ⇒
|
||||
.handle { case ValidationRejection(msg, _) =>
|
||||
complete((InternalServerError, "That wasn't valid! " + msg))
|
||||
}
|
||||
.handleAll[MethodRejection] { methodRejections ⇒
|
||||
.handleAll[MethodRejection] { methodRejections =>
|
||||
val names = methodRejections.map(_.supported.name)
|
||||
complete((MethodNotAllowed, s"Can't do that! Supported: ${names mkString " or "}!"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class WebSocketExampleSpec extends WordSpec with Matchers {
|
|||
// rather we simply stream it back as the tail of the response
|
||||
// this means we might start sending the response even before the
|
||||
// end of the incoming message has been received
|
||||
case tm: TextMessage ⇒ TextMessage(Source.single("Hello ") ++ tm.textStream) :: Nil
|
||||
case tm: TextMessage => TextMessage(Source.single("Hello ") ++ tm.textStream) :: Nil
|
||||
case bm: BinaryMessage =>
|
||||
// ignore binary messages but drain content to avoid the stream being clogged
|
||||
bm.dataStream.runWith(Sink.ignore)
|
||||
|
|
@ -43,13 +43,13 @@ class WebSocketExampleSpec extends WordSpec with Matchers {
|
|||
//#websocket-handler
|
||||
|
||||
//#websocket-request-handling
|
||||
val requestHandler: HttpRequest ⇒ HttpResponse = {
|
||||
case req @ HttpRequest(GET, Uri.Path("/greeter"), _, _, _) ⇒
|
||||
val requestHandler: HttpRequest => HttpResponse = {
|
||||
case req @ HttpRequest(GET, Uri.Path("/greeter"), _, _, _) =>
|
||||
req.header[UpgradeToWebSocket] match {
|
||||
case Some(upgrade) ⇒ upgrade.handleMessages(greeterWebSocketService)
|
||||
case None ⇒ HttpResponse(400, entity = "Not a valid websocket request!")
|
||||
case Some(upgrade) => upgrade.handleMessages(greeterWebSocketService)
|
||||
case None => HttpResponse(400, entity = "Not a valid websocket request!")
|
||||
}
|
||||
case _: HttpRequest ⇒ HttpResponse(404, entity = "Unknown resource!")
|
||||
case _: HttpRequest => HttpResponse(404, entity = "Unknown resource!")
|
||||
}
|
||||
//#websocket-request-handling
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ class WebSocketExampleSpec extends WordSpec with Matchers {
|
|||
import system.dispatcher // for the future transformations
|
||||
bindingFuture
|
||||
.flatMap(_.unbind()) // trigger unbinding from the port
|
||||
.onComplete(_ ⇒ system.terminate()) // and shutdown when done
|
||||
.onComplete(_ => system.terminate()) // and shutdown when done
|
||||
}
|
||||
"routing-example" in {
|
||||
pending // compile-time only test
|
||||
|
|
@ -83,7 +83,7 @@ class WebSocketExampleSpec extends WordSpec with Matchers {
|
|||
val greeterWebSocketService =
|
||||
Flow[Message]
|
||||
.collect {
|
||||
case tm: TextMessage ⇒ TextMessage(Source.single("Hello ") ++ tm.textStream)
|
||||
case tm: TextMessage => TextMessage(Source.single("Hello ") ++ tm.textStream)
|
||||
// ignore binary messages
|
||||
}
|
||||
|
||||
|
|
@ -104,6 +104,6 @@ class WebSocketExampleSpec extends WordSpec with Matchers {
|
|||
import system.dispatcher // for the future transformations
|
||||
bindingFuture
|
||||
.flatMap(_.unbind()) // trigger unbinding from the port
|
||||
.onComplete(_ ⇒ system.terminate()) // and shutdown when done
|
||||
.onComplete(_ => system.terminate()) // and shutdown when done
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -267,14 +267,14 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
|||
|
||||
private def nonSuccessToEmptyJsonEntity(response: HttpResponse): HttpResponse =
|
||||
response.status match {
|
||||
case code if code.isSuccess ⇒ response
|
||||
case code ⇒
|
||||
case code if code.isSuccess => response
|
||||
case code =>
|
||||
log.warning("Dropping response entity since response status code was: {}", code)
|
||||
response.copy(entity = NullJsonEntity)
|
||||
}
|
||||
|
||||
/** Wrapper for all of our JSON API routes */
|
||||
def apiRoute(innerRoutes: ⇒ Route): Route =
|
||||
def apiRoute(innerRoutes: => Route): Route =
|
||||
mapResponse(nonSuccessToEmptyJsonEntity)(innerRoutes)
|
||||
}
|
||||
//#
|
||||
|
|
@ -388,13 +388,12 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
|||
"mapInnerRoute" in {
|
||||
//#mapInnerRoute
|
||||
val completeWithInnerException =
|
||||
mapInnerRoute { route =>
|
||||
ctx =>
|
||||
try {
|
||||
route(ctx)
|
||||
} catch {
|
||||
case NonFatal(e) => ctx.complete(s"Got ${e.getClass.getSimpleName} '${e.getMessage}'")
|
||||
}
|
||||
mapInnerRoute { route => ctx =>
|
||||
try {
|
||||
route(ctx)
|
||||
} catch {
|
||||
case NonFatal(e) => ctx.complete(s"Got ${e.getClass.getSimpleName} '${e.getMessage}'")
|
||||
}
|
||||
}
|
||||
|
||||
val route =
|
||||
|
|
@ -801,4 +800,4 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
|||
//#
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ class HeaderDirectivesExamplesSpec extends RoutingSpec with Inside {
|
|||
}
|
||||
"headerValueByType-0" in {
|
||||
val route =
|
||||
headerValueByType[Origin]() { origin ⇒
|
||||
headerValueByType[Origin]() { origin =>
|
||||
complete(s"The first origin was ${origin.origins.head}")
|
||||
}
|
||||
|
||||
|
|
@ -161,14 +161,14 @@ class HeaderDirectivesExamplesSpec extends RoutingSpec with Inside {
|
|||
|
||||
// reject a request if no header of the given type is present
|
||||
Get("abc") ~> route ~> check {
|
||||
inside(rejection) { case MissingHeaderRejection("Origin") ⇒ }
|
||||
inside(rejection) { case MissingHeaderRejection("Origin") => }
|
||||
}
|
||||
}
|
||||
"optionalHeaderValueByType-0" in {
|
||||
val route =
|
||||
optionalHeaderValueByType[Origin]() {
|
||||
case Some(origin) ⇒ complete(s"The first origin was ${origin.origins.head}")
|
||||
case None ⇒ complete("No Origin header found.")
|
||||
case Some(origin) => complete(s"The first origin was ${origin.origins.head}")
|
||||
case None => complete("No Origin header found.")
|
||||
}
|
||||
|
||||
val originHeader = Origin(HttpOrigin("http://localhost:8080"))
|
||||
|
|
|
|||
|
|
@ -67,13 +67,13 @@ class MiscDirectivesExamplesSpec extends RoutingSpec {
|
|||
Language("de") withQValue 0.5f)
|
||||
|
||||
request ~> {
|
||||
selectPreferredLanguage("en", "en-US") { lang ⇒
|
||||
selectPreferredLanguage("en", "en-US") { lang =>
|
||||
complete(lang.toString)
|
||||
}
|
||||
} ~> check { responseAs[String] shouldEqual "en-US" }
|
||||
|
||||
request ~> {
|
||||
selectPreferredLanguage("de-DE", "hu") { lang ⇒
|
||||
selectPreferredLanguage("de-DE", "hu") { lang =>
|
||||
complete(lang.toString)
|
||||
}
|
||||
} ~> check { responseAs[String] shouldEqual "de-DE" }
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class SchemeDirectivesExamplesSpec extends RoutingSpec {
|
|||
|
||||
val route =
|
||||
scheme("http") {
|
||||
extract(_.request.uri) { uri ⇒
|
||||
extract(_.request.uri) { uri =>
|
||||
redirect(uri.copy(scheme = "https"), MovedPermanently)
|
||||
}
|
||||
} ~
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ class TimeoutDirectivesExamplesSpec extends RoutingSpec with CompileOnlySpec {
|
|||
|
||||
"allow mapping the response while setting the timeout" in compileOnlySpec {
|
||||
//#withRequestTimeout-with-handler
|
||||
val timeoutResponse = HttpResponse(StatusCodes.EnhanceYourCalm,
|
||||
val timeoutResponse = HttpResponse(
|
||||
StatusCodes.EnhanceYourCalm,
|
||||
entity = "Unable to serve response within time limit, please enchance your calm.")
|
||||
|
||||
val route =
|
||||
|
|
@ -57,7 +58,8 @@ class TimeoutDirectivesExamplesSpec extends RoutingSpec with CompileOnlySpec {
|
|||
pending // compile only spec since requires actuall Http server to be run
|
||||
|
||||
//#withRequestTimeoutResponse
|
||||
val timeoutResponse = HttpResponse(StatusCodes.EnhanceYourCalm,
|
||||
val timeoutResponse = HttpResponse(
|
||||
StatusCodes.EnhanceYourCalm,
|
||||
entity = "Unable to serve response within time limit, please enchance your calm.")
|
||||
|
||||
val route =
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ class WebSocketDirectivesExamplesSpec extends RoutingSpec {
|
|||
"greeter-service" in {
|
||||
def greeter: Flow[Message, Message, Any] =
|
||||
Flow[Message].mapConcat {
|
||||
case tm: TextMessage ⇒
|
||||
case tm: TextMessage =>
|
||||
TextMessage(Source.single("Hello ") ++ tm.textStream ++ Source.single("!")) :: Nil
|
||||
case bm: BinaryMessage ⇒
|
||||
case bm: BinaryMessage =>
|
||||
// ignore binary messages but drain content to avoid the stream being clogged
|
||||
bm.dataStream.runWith(Sink.ignore)
|
||||
Nil
|
||||
|
|
@ -59,9 +59,9 @@ class WebSocketDirectivesExamplesSpec extends RoutingSpec {
|
|||
"handle-multiple-protocols" in {
|
||||
def greeterService: Flow[Message, Message, Any] =
|
||||
Flow[Message].mapConcat {
|
||||
case tm: TextMessage ⇒
|
||||
case tm: TextMessage =>
|
||||
TextMessage(Source.single("Hello ") ++ tm.textStream ++ Source.single("!")) :: Nil
|
||||
case bm: BinaryMessage ⇒
|
||||
case bm: BinaryMessage =>
|
||||
// ignore binary messages but drain content to avoid the stream being clogged
|
||||
bm.dataStream.runWith(Sink.ignore)
|
||||
Nil
|
||||
|
|
@ -85,7 +85,7 @@ class WebSocketDirectivesExamplesSpec extends RoutingSpec {
|
|||
WS("/services", wsClient.flow, List("other", "echo")) ~>
|
||||
websocketMultipleProtocolRoute ~>
|
||||
check {
|
||||
expectWebSocketUpgradeWithProtocol { protocol ⇒
|
||||
expectWebSocketUpgradeWithProtocol { protocol =>
|
||||
protocol shouldEqual "echo"
|
||||
|
||||
wsClient.sendMessage("Peter")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue