extractRequest directive is not working inside a method that returns Directive0

Viewed 18

I am new to scala and I am trying to implement CORS mechanism on my Scala Application. We have 2 methods in my app one ads the CORS headers to Preflight OPTIONS request and other one that ads headers to all other responses. below are the methods

private def preflightRequestHandler: Route = options { complete(HttpResponse(StatusCodes.OK).withHeaders(Access-Control-Allow-Methods(OPTIONS, POST, PUT, GET, DELETE))) }

method2

Now, I am trying to get the current HTTP request inside my addAccessControlHeaders method via extractRequest Directive but whatever the code I have written inside extractRequest is not getting executed. I could use exractRequest directive in the first method ( preflight handler) but not on the second method. Can we use extractRequest inside a method that is returning a Directive? if not how can we get the current HttpRequest in scala.

0 Answers
Related