simulate method

Future<SimulatedResponse> simulate(
  1. Request req
)

Simulate the processing of a HTTP request.

This is used for testing a server.

Pass in a Request for the server to process. This will be a Request created using one of these constructors: Request.simulated, Request.simulatedGet or Request.simulatedPost.

The response returned can then be examined to determine if the server produced the expected HTTP response.

Implementation

Future<SimulatedResponse> simulate(Request req) async {
  // Set the server for the request. This is done here, so a simulated
  // request doesn't need to have its server set when it is constructed.

  req._server = this;

  // Get the server to process the request

  _logRequest.fine('[${req.id}] ${req.method} ${req.requestPath()}');

  await _processRequest(req);

  // Return the response

  final result = req._simulatedResponse;

  // Once the simulation has finished, the [req._server] becomes meaningless.
  // Previously, this code reset it back to null. But with null safety,
  // it cannot be null, so the value of the request's [_server] remains set.
  // Just don't use it outside of a simulated run.

  return result;
}