I am having an issue where I am not able to receive request that have illegal encoding, namely %%
. An example URL would be 127.0.0.1/path?test=%%val%%
If I make a request to this URL I receive an error: Illegal request-target: Invalid input '%', expected HEXDIG (line 1, column 13)
. I have tried creating an exception handler, rejection handler, and setting uri-parsing-mode = relaxed
. Ideally I could somehow get the raw data in these cases and process the request anyway, as despite having bad encoding, they are still a valid request for my use case, but being able to handle the exception would probably be enough. Being unable to process these requests would result in unacceptable data loss in my case. Here is an my current test snippet:
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.HttpMethods._
import akka.http.scaladsl.server.Directives._
import scala.io.StdIn
import akka.http.scaladsl.server._
import akka.http.scaladsl.model._
object Main extends App {
implicit def myRejectionHandler =
RejectionHandler.newBuilder()
.handle {
case _: IllegalUriException =>
println("Illegal URI rejection")
complete(HttpResponse(200))
}
.handleAll[MethodRejection] { methodRejections =>
println("Handle all")
complete(HttpResponse(200))
}
.result()
implicit def myExceptionHandler: ExceptionHandler =
ExceptionHandler {
case _: IllegalUriException =>
println ("Illegal URI Exception")
complete(HttpResponse(200))
}
implicit val system = ActorSystem()
implicit val executionContext = system.dispatcher
val route = {
handleExceptions(myExceptionHandler) {
get {
path("path") {
complete("path!")
}
}
}
}
val bindingFuture = Http().newServerAt("0.0.0.0", 80).bind(route)
println(s"Server online at http://localhost:80/\nPress RETURN to stop...")
StdIn.readLine()
bindingFuture
.flatMap(_.unbind())
.onComplete(_ => system.terminate())
}