Request.simulated constructor
- String method,
- String internalPath, {
- String? id,
- String? sessionId,
- RequestParams? queryParams,
- HttpConnectionInfo? connectionInfo,
- X509Certificate? certificate,
- SimulatedHttpHeaders? headers,
- List<
Cookie> ? cookies, - String? bodyStr,
- List<
int> ? bodyBytes, - int? bodyStreamEventSize,
- RequestParams? postParams,
Creates a simulated request.
A simulated HTTP request is used for testing a server. The simulated request is "sent" to the server using the Server.simulate method. This is an alternative to testing by sending real HTTP requests to it over the network.
The request has the HTTP method (e.g. "GET", "POST", "PATCH") and
is for the internalPath (a string starting with "~/").
The id is an identifier for the request. This identifier is used in any
log entries about the request. If not provided, an identifier will
be generated ("SIM:" followed by a number).
The sessionId is identifier of a session. Sessions are optional.
The queryParams contain the query parameters of the request.
Conceptually, the URL of the request would include the internalPath
and any queryParameters.
The connectionInfo contains the information about the connection the
request was sent over. In a simulated request, no real network connection
is involved. But a value can be provided for it, for use by the
request handler (e.g. to test logging or to allow list checking).
The client certificate for the TLS connect the request was sent over.
In a simulated request, no real TLS connection is involved. But a
value can be provided for the client certificate, for use by the request
handler (e.g. to test client authentication using client certificates).
The HTTP headers contains the headers of the request.
The cookies contains the cookies of the request.
The body of the request can be provided as bodyBytes or bodyStr.
If neither is provided, the body is empty. Do not provide both.
If the request handler retrieves the body as a stream using
Request.bodyStream, bodyStreamEventSize is the maximum number
of bytes in each event from the stream.
Implementation
Request.simulated(String method, String internalPath,
{String? id,
String? sessionId,
RequestParams? queryParams,
HttpConnectionInfo? connectionInfo,
X509Certificate? certificate,
SimulatedHttpHeaders? headers,
List<Cookie>? cookies,
String? bodyStr,
List<int>? bodyBytes,
int? bodyStreamEventSize,
this.postParams})
: _id = id ?? _defaultSimulatedId,
queryParams = queryParams ?? RequestParams._internalConstructor(),
_sessionUsingCookies = true,
_coreRequest = _CoreRequestSimulated(method, internalPath,
sessionId: sessionId ?? '',
queryParams: queryParams,
certificate: certificate,
connectionInfo: connectionInfo,
headers: headers ?? SimulatedHttpHeaders(),
cookies: cookies ?? <Cookie>[],
bodySteamEventSize: bodyStreamEventSize,
bodyStr: bodyStr,
bodyBytes: bodyBytes),
_coreResponse = _CoreResponseSimulated() {
_constructorCommon();
}