Class DefaultHttpClientFactory

java.lang.Object
io.karatelabs.http.DefaultHttpClientFactory
All Implemented Interfaces:
HttpClientFactory

public class DefaultHttpClientFactory extends Object implements HttpClientFactory
Default implementation of HttpClientFactory that creates a new ApacheHttpClient instance for each call.

This is the standard behavior for functional tests where each test scenario should have an isolated HTTP client with its own configuration and state.

For performance testing with connection pooling, supply a custom factory. No such factory ships today — this javadoc used to point at a PooledHttpClientFactory in karate-gatling that does not exist. If you write one, read the contract on HttpClientFactory.release(io.karatelabs.http.HttpClient) first: it must return a distinct wrapper per scenario and share the connection manager beneath them, because ApacheHttpClient closes its own transport on apply().

See Also:
  • Constructor Details

    • DefaultHttpClientFactory

      public DefaultHttpClientFactory()
  • Method Details

    • create

      public HttpClient create()
      Description copied from interface: HttpClientFactory
      Creates a new HttpClient instance.
      Specified by:
      create in interface HttpClientFactory
      Returns:
      a new HttpClient instance
    • release

      public void release(HttpClient client)
      Closes it. This factory hands out one client per scenario and nothing else can reach it, so the scenario's end is the last moment anyone can release its sockets deterministically.

      Every ScenarioRuntime builds its own client — including one per karate.call() — and none of them used to be closed.

      Specified by:
      release in interface HttpClientFactory
      Parameters:
      client - a client previously returned by HttpClientFactory.create()