我们有 Unfiltered 与底层 Jetty 服务器(不确定,但我相信 Unfiltered 使用 Jetty 8)。现在我们需要为我们返回的所有响应添加标题条目。
我可以获得底层的 Jetty Server 并尝试将 Handler 直接添加到它。不确定我是否犯了一些愚蠢的错误或 Unfiltered 是否做了某些事情,因为我设法添加了该标题,但同时我删除了所有其他功能。不好 :)
我还在 jetty.xml 中找到了这样做的方法,但没有得到它的工作。
现在尝试让它与 Cycle.Intent 一起使用,但是在将其中两个添加到 Plan 时遇到类型问题。
object AllowOrigin {
case class AllowOriginResponseFunctionWrapper[A](req: HttpRequest[A], f: ResponseFunction[Any]) extends ResponseFunction[Any] {
def apply[T](res: HttpResponse[T]) = req match {
case _ =>
val resp = f(res)
resp.header("Access-Control-Allow-Origin", "*")
resp
}
}
def apply[A](inner: Cycle.Intent[A,Any]): Cycle.Intent[A,Any] = {
case req @ _ => {
inner.orElse({ case _ => Pass }: Cycle.Intent[A,Any])(req) match {
case Pass => Pass
case responseFunction => AllowOriginResponseFunctionWrapper(req, responseFunction)
}
}
}
}