private def proxy()

in app/com/gu/viewer/proxy/ProxyClient.scala [18:49]


  private def proxy(
             method: String,
             destination: String,
             headers: Seq[(String, String)] = Seq.empty,
             cookies: Seq[Cookie] = Seq.empty,
             queryString: Seq[(String, String)] = Seq.empty,
             body: Map[String, Seq[String]] = Map.empty,
             followRedirects: Boolean = false
             )(handler: PartialFunction[ProxyResponse, Future[ProxyResult]] = PartialFunction.empty): Future[ProxyResult] = {

    val cookieHeader = if (cookies.nonEmpty) Some(COOKIE -> encodeCookieHeader(cookies)) else None

    val contentLengthHeader = if (body.nonEmpty) Some(CONTENT_LENGTH -> body.size.toString) else None

    val userAgentHeader = Some(USER_AGENT -> s"gu-viewer ${config.stage}")

    def handleResponse: PartialFunction[ProxyResponse, Future[ProxyResult]] = {
      case response =>
        Future.successful(ProxyResultWithBody(response))
    }

    ws.url(destination)
      .withFollowRedirects(follow = followRedirects)
      .withHttpHeaders(headers ++ contentLengthHeader ++ userAgentHeader ++ cookieHeader: _*)
      .withQueryStringParameters(queryString: _*)
      .withRequestTimeout(TIMEOUT)
      .withBody(body)
      .withMethod(method)
      .stream()
        .map(new ProxyResponse(_))
        .flatMap(handler orElse handleResponse)
  }