从Play WS获取ahcResponse

时间:2014-08-07 07:59:25

标签: scala playframework-2.3 asynchttpclient

我有这个:

class RichResponse(future: Future[WSResponse]) {

  def failIfNot(statuses: Int*)(implicit executor: ExecutionContext) = {
    future.map { response =>
      if(statuses.contains(response.status)) {
        response
      } else {
        throw new RuntimeException("Bad HTTP response for %s: %s".format(
          response.ahcResponse.getUri, response.status))
      }
    }
  }

}

object Implicits {

  implicit def responseToRichResponse(future: Future[WSResponse]) = new RichResponse(future)

}

用法是这样的:

WS.url("http://stackoverflow.com/questions/ask").failIfNot(OK)

但是从2.1升级到2.3后,achResponse不再存在。如何获得底层(并且更完整)的响应对象?

1 个答案:

答案 0 :(得分:1)

我开始阅读源代码,似乎

response.underlying[NingWSResponse].ahcResponse

将是实现此目的的新方法。

似乎不太安全....