HttpWaitStrategy class
Waits until an HTTP endpoint inside the container returns an acceptable response.
On each poll attempt the strategy sends an HTTP request to the container and checks:
- The response status code (against forStatusCode or forStatusCodeMatching).
- Optionally, the response body (via forResponsePredicate).
Each individual request times out after 1 second. SocketException,
TimeoutException, and http.ClientException are treated as transient
failures.
Example:
container.waitingFor(
HttpWaitStrategy(8080, path: '/health')
.forStatusCode(200)
..withStartupTimeout(const Duration(seconds: 60)),
);
- Inheritance
-
- Object
- WaitStrategy
- HttpWaitStrategy
Constructors
- HttpWaitStrategy(int port, {String path = '/'})
-
Creates an HttpWaitStrategy that probes
portatpath. - HttpWaitStrategy.fromUrl(String url)
-
Creates an HttpWaitStrategy from a full URL string.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- path → String
-
The URL path to request. Always starts with
/.final - pollInterval ↔ Duration
-
Time between successive polling attempts.
getter/setter pairinherited
- port → int
-
The container port to probe.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- startupTimeout ↔ Duration
-
Maximum time to wait for the container to become ready.
getter/setter pairinherited
-
testHeaders
→ Map<
String, String> -
The current set of HTTP headers that will be sent with each probe request.
no setter
- testMethod → String
-
The HTTP method that will be used for each probe request.
no setter
-
testStatusCodes
→ Set<
int> -
The set of HTTP status codes that are considered successful.
no setter
Methods
-
forResponsePredicate(
bool predicate(String)) → HttpWaitStrategy - Adds an additional response body check on top of the status-code check.
-
forStatusCode(
int code) → HttpWaitStrategy -
Adds
codeto the set of acceptable HTTP status codes. -
forStatusCodeMatching(
bool matcher(int)) → HttpWaitStrategy -
Replaces the status-code check with a custom
matcherfunction. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
poll(
Future< bool> check(), {List<Type> ? transientExceptions}) → Future<bool> -
Adaptive polling loop.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
usingTls(
{bool insecure = false}) → HttpWaitStrategy -
Switches the request scheme to
https. -
waitUntilReady(
WaitStrategyTarget target) → Future< void> -
Polls the HTTP endpoint until an acceptable response is received.
override
-
withBasicCredentials(
String username, String password) → HttpWaitStrategy - Sets HTTP Basic authentication credentials.
-
withBody(
String body) → HttpWaitStrategy - Sets a request body to include with each probe request.
-
withHeader(
String name, String value) → HttpWaitStrategy - Adds a custom HTTP request header.
-
withMethod(
String method) → HttpWaitStrategy - Sets the HTTP method used for each probe request.
-
withPollInterval(
Duration interval) → WaitStrategy -
Sets the poll interval between readiness checks.
inherited
-
withStartupTimeout(
Duration timeout) → WaitStrategy -
Sets the maximum startup timeout.
inherited
-
withTransientExceptions(
List< Type> exceptions) → WaitStrategy -
Adds
exceptionsto the set of exception types that are treated as transient failures during polling.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited