2014-02-25 61 views
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]] 
) 

有反正解組時訪問他們?有什麼解決辦法嗎?

+1

如果您提供'FromResponseUnmarshaller'而不是簡單的'Unmarshaller',您還可以訪問標題。 – jrudolph

+0

感謝您的建議。你知道是否有任何工廠方法來創建'FromResponseUnmarshaller'? – paradigmatic

+1

查看此文件以獲取創建'FromResponseUnmarshallers'的方法:https://github.com/spray/spray/blob/master/spray-httpx/src/main/scala/spray/httpx/unmarshalling/Deserializer.scala – jrudolph

回答