我使用spray-client访问REST服务。服务器返回的部分数据位于http响应头中(其余数据在响应主体中)。
为了能够解开响应,我使用了一个Unmarshaller。然而,解组程序只能访问响应体(作为HttpEntity的一个实例),并且在这个阶段所有的头似乎都是不可访问的。
下面是当前管道和解编组程序代码:
implicit val IDsUnmarshaller =
Unmarshaller[List[ID]](MediaTypes.`text/plain`) {
case HttpEntity.NonEmpty(contentType, data) =>
data.asString.split("\n").toList.map( ID(_) )
}
val pipeline: HttpRequest => Future[List[ID]] = (
encode(Gzip)
~> sendReceive
~> decode(Deflate)
~> unmarshal[List[ID]]
)解编组时是否有访问它们的权限?附近有工作吗?
发布于 2015-06-06 05:58:56
如果您提供的是FromResponseUnmarshaller而不是普通的解组程序,您也可以访问标头。
有关创建FromResponseUnmarshallers:https://github.com/spray/spray/blob/master/spray-httpx/src/main/scala/spray/httpx/unmarshalling/Deserializer.scala的方法,请参阅此文件
例如,您可以提供一个隐式函数HttpResponse => List[ID],这个函数应该被选中。
https://stackoverflow.com/questions/22015692
复制相似问题