Scala 从响应中排除特定标题
如何从响应中删除标题(SimpleResult) 代码示例:Scala 从响应中排除特定标题,scala,playframework-2.0,Scala,Playframework 2.0,如何从响应中删除标题(SimpleResult) 代码示例: def NoCache[A](action: Action[A]): Action[A] = Action(action.parser) { request => action(request) match { case s: SimpleResult[_] => s.withHeaders(PRAGMA -> "no-cache") // re
def NoCache[A](action: Action[A]): Action[A] = Action(action.parser) { request =>
action(request) match {
case s: SimpleResult[_] =>
s.withHeaders(PRAGMA -> "no-cache")
// remove all headers with name "ETAG" HERE ??
case result => result
}
}
我在文档中没有找到此功能
谢谢。由于
SimpleResult
和ResponseHeader
都是案例类,您可以复制它们来修改标题:
...
val headers = s.header.headers - ETAG + (PRAGMA -> "no-cache")
s.copy(header = s.header.copy(headers = headers))
...
你好,不幸的是,这不起作用。scala:无法将HTTP响应的实例写入。尝试定义涉及默认参数的应用程序中发生的可写[a]错误。s、 复制(header=s.header.copy(headers=headers))^它可能在SimpleResult类中工作