simulate method

Future<SimulatedResponse> simulate (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._serverSet(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;

  // Clear server in the simulated request, so it can be set in the future
  req._serverSet(null); // must do this AFTER calling req._simulatedResponse.

  return result;
}