I'll get my colleague to post something
He did the work
On 17 Jun 2015 15:34, "Mariano Treb" <[email protected]> wrote:

> I am having the same problem!!! How did you solved it? I have been working
> for days and I cant find any good solution.
>
> El martes, 10 de marzo de 2015, 18:48:09 (UTC+1), Tim Pigden escribió:
>>
>> This thread may help:
>>
>> https://groups.google.com/forum/#!searchin/akka-user/cors/akka-user/msJfSkHDCxA/foDrnQPBx2gJ
>>
>> I've not got around to looking at it yet.
>>
>>
>> On Tuesday, March 10, 2015 at 2:14:53 PM UTC, Ganta Murali Krishna wrote:
>>>
>>> Hello,
>>>
>>> I am currently experimenting with Akka-http on one of our modules. *Below
>>> (or attached) is my current CORS file for spray*. I am struggling with
>>> conversion, for e.g.: I cant find alternative to mapRequestContext. Can
>>> any help me to rewrite/convert this please. So I can use this with
>>> akka-http. Any help is appreciated.
>>>
>>> Regards
>>> Murali
>>>
>>> import spray.http.{HttpMethods, HttpMethod, HttpResponse, AllOrigins}
>>> import spray.http.HttpHeaders._
>>> import spray.http.HttpMethods._
>>> import spray.routing._
>>>
>>> trait CORSSupport {
>>>   this: HttpService =>
>>>   private val allowOriginHeader = `Access-Control-Allow-Origin`(AllOrigins)
>>>   private val optionsCorsHeaders = List(
>>>     `Access-Control-Allow-Headers`("Origin, 
>>> X-Requested-With,Authorization,Content-Type, Accept, Accept-Encoding, 
>>> Accept-Language, Host, Referer, User-Agent,apiKey"),
>>>     `Access-Control-Max-Age`(1728000))
>>>
>>>   def cors[T]: Directive0 = mapRequestContext { ctx => 
>>> ctx.withRouteResponseHandling({
>>>     //It is an option requeset for a resource that responds to some other 
>>> method
>>>     case Rejected(x) if (ctx.request.method.equals(HttpMethods.OPTIONS) && 
>>> !x.filter(_.isInstanceOf[MethodRejection]).isEmpty) => {
>>>       val allowedMethods: List[HttpMethod] = 
>>> x.filter(_.isInstanceOf[MethodRejection]).map(rejection => {
>>>         rejection.asInstanceOf[MethodRejection].supported
>>>       })
>>>       ctx.complete(HttpResponse().withHeaders(
>>>         `Access-Control-Allow-Methods`(OPTIONS, allowedMethods: _*) :: 
>>> allowOriginHeader ::
>>>           optionsCorsHeaders
>>>       ))
>>>     }
>>>   }).withHttpResponseHeadersMapped { headers =>
>>>     allowOriginHeader :: headers
>>>   }
>>>   }
>>> }
>>>
>>>  --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ:
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Akka User List" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/akka-user/5RCZIJt7jHo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to