3
我正在使用spray-client
来访问REST服务。部分服务器返回的数据位于http响应头中(其余部分位于响应正文中)。使用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]]
)
有反正解组时访问他们?有什么解决办法吗?
如果您提供'FromResponseUnmarshaller'而不是简单的'Unmarshaller',您还可以访问标题。 – jrudolph
感谢您的建议。你知道是否有任何工厂方法来创建'FromResponseUnmarshaller'? – paradigmatic
查看此文件以获取创建'FromResponseUnmarshallers'的方法:https://github.com/spray/spray/blob/master/spray-httpx/src/main/scala/spray/httpx/unmarshalling/Deserializer.scala – jrudolph