package client


import ratpack.exec.ExecResult

class RatpackForkedHttpClientTest extends RatpackHttpClientTest {

  @Override
  int doRequest(String method, URI uri, Map<String, String> headers, String body, Closure callback) {
    ExecResult<Integer> result = exec.yield {
      def resp = client.request(uri) { spec ->
        spec.method(method)
        spec.headers { headersSpec ->
          headers.entrySet().each {
            headersSpec.add(it.key, it.value)
          }
        }
      }
      return resp.fork().map {
        callback?.call()
        it.status.code
      }
    }
    return result.value
  }
}
