Last active
April 27, 2017 11:58
-
-
Save jlprat/a627e7f9d0d1d83f51099a8bf1218d6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ERROR] [04/27/2017 13:41:56.845] [pool-6-thread-8-ScalaTest-running-PathDirectivesSpec] [akka.actor.ActorSystemImpl(akka-http-scaladsl-server-directives-PathDirectivesSpec)] Error during processing of request: 'Rejection handler still produced new rejections after 8 iterations. Is there an infinite handler cycle? Initial rejections: List() final rejections: List()'. Completing with 500 Internal Server Error response. To change default exception handling behavior, provide a custom ExceptionHandler. | |
java.lang.RuntimeException: Rejection handler still produced new rejections after 8 iterations. Is there an infinite handler cycle? Initial rejections: List() final rejections: List() | |
at scala.sys.package$.error(package.scala:27) | |
at akka.http.scaladsl.server.directives.ExecutionDirectives$$anonfun$handleRejections$1.akka$http$scaladsl$server$directives$ExecutionDirectives$class$$anonfun$$handle$1(ExecutionDirectives.scala:55) | |
at akka.http.scaladsl.server.directives.ExecutionDirectives$$anonfun$handleRejections$1$$anonfun$akka$http$scaladsl$server$directives$ExecutionDirectives$class$$anonfun$$handle$1$1.apply(ExecutionDirectives.scala:51) | |
at akka.http.scaladsl.server.directives.ExecutionDirectives$$anonfun$handleRejections$1$$anonfun$akka$http$scaladsl$server$directives$ExecutionDirectives$class$$anonfun$$handle$1$1.apply(ExecutionDirectives.scala:51) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ignoreTrailingSlash: Directive0 = Directive[Unit] { inner ⇒ | |
import ExecutionDirectives._ | |
val totallyMissingHandler = RejectionHandler.newBuilder() | |
.handleNotFound { | |
mapRequestContext(req ⇒ req.withUnmatchedPath(flipTrailingSlash(req.unmatchedPath)))(inner()) | |
} | |
.result() | |
handleRejections(totallyMissingHandler) { | |
inner() | |
} | |
} | |
/// TESTS | |
"the `ignoreTrailingSlash` directive" should { | |
val route = ignoreTrailingSlash { | |
path("foo") { completeOk } ~ | |
(pathPrefix("bar") & pathEndOrSingleSlash) { completeOk } | |
} | |
"pass if the request path doesn't have a trailing slash" in { | |
Get("/foo") ~> route ~> check { response shouldEqual Ok } | |
} | |
"pass if the request path has a trailing slash" in { | |
Get("/foo/") ~> route ~> check { response shouldEqual Ok } | |
} | |
"do only 1 pass if path already checks for trailing slash" in { | |
Get("/bar/") ~> route ~> check { response shouldEqual Ok } | |
} | |
"reject if request can't be matched with nor without a trailing slash" in { | |
Get("/foz") ~> route ~> check { | |
println(response) | |
handled shouldEqual false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment