1
votes

According to pathEnd directive's documentation:

Rejects the request if the unmatchedPath of the [[RequestContext]] is non-empty, or said differently: only passes on the request to its inner route if the request path has been matched completely.

But:

val route = pathPrefix("prefix") {
      get {
        pathEnd {
          complete(HttpEntity("test\n"))
        }
      }
    }

catches GET requests on path "/prefix?something" or "/prefix?something=z", etc...

Is this normal behaviour? How could I make it reject the example paths above?

Thanks

I'm using akka 2.4.4

1

1 Answers

3
votes

This is normal behavior. The query string is not part of the request path and is therefore not matched. To reject these requests, you could explicitly check that the parameter set is empty:

val route =
  pathPrefix("prefix") {
    get {
      pathEnd {
        parameterSeq { params =>
          validate(params.isEmpty, "Parameters must be empty") {
            complete(HttpEntity("test\n"))
          }
        }
      }
    }
  }

Get("/prefix") ~> route ~> check {
  responseAs[String] shouldEqual "test\n"
}

Get("/prefix?something") ~> route ~> check {
  rejection shouldEqual ValidationRejection("Parameters must be empty")
}