Package io.karatelabs.http
Class DefaultHttpClientFactory
java.lang.Object
io.karatelabs.http.DefaultHttpClientFactory
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreate()Creates a new HttpClient instance.voidrelease(HttpClient client) Closes it.
-
Constructor Details
-
DefaultHttpClientFactory
public DefaultHttpClientFactory()
-
-
Method Details
-
create
Description copied from interface:HttpClientFactoryCreates a new HttpClient instance.- Specified by:
createin interfaceHttpClientFactory- Returns:
- a new HttpClient instance
-
release
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:
releasein interfaceHttpClientFactory- Parameters:
client- a client previously returned byHttpClientFactory.create()
-