Play Framework 2.2.1 - Case Insensitive

I am new to Play and currently working on Play 2.2.1

I am trying to achieve case insensitivity for my endpoints that are defined in "routes"

eg. I defined the say / accessLicense route in the routes file, it will look below

GET /accessLicense controller.MyController.accessLicense()

Now, if I shoot / accessLicense, it works fine; as expected, but if you try to use fir / AccessLicense, / AcCeSSLicenSe or any other combination of upper and lower case letters that pronounces the same word, it does not work.

Thank you in advance for your guidance and support !!!

+6
source share
1 answer

Unfortunately, AFAIK, there is no way to magically turn on a switch that will do what you want. Fortunately, there is a workaround inferior to IMHO, but its the best you can do.

GET / [aA] [cC] [cC] [eE] [sS] [sS] .....

EDIT: I did the following that matches my specific requirement for the bottom of the body is only the first part of the URL. Thus, GET / AbCdE / XyZ will become GET / abcde / XyZ, and if it has an action in the routes, then it will be processed accordingly.

 override def onRouteRequest( request: RequestHeader ) = { val path = request.path val split = path.split( "/" ).toList val lowerCasePath = split match{ case ""::Nil => ""::Nil case ""::x::y => ""::x.toLowerCase::y } logger.error( lowerCasePath.toString ) super.onRouteRequest( request.copy( path = lowerCasePath.mkString( "/" ) ) ) } 

EDIT See here: https://jazzy.id.au/2013/05/08/advanced_routing_in_play_framework.html

+2
source

All Articles