MockHttpRequest constructor

MockHttpRequest({
  1. String method = 'GET',
  2. Uri? uri,
  3. String? body,
  4. List<int>? bodyBytes,
  5. Map<String, String>? headers,
  6. String remoteIp = '127.0.0.1',
  7. int? contentLength,
})

Creates a mock HTTP request.

  • method: HTTP method (GET, POST, etc.)
  • uri: Request URI with path and query parameters
  • body: Request body as string (will be UTF-8 encoded)
  • bodyBytes: Request body as bytes (alternative to body)
  • headers: Map of header name to value
  • remoteIp: Client IP address for testing IP-based logic
  • contentLength: Override Content-Length (for testing body limit checks)

Implementation

MockHttpRequest({
  this.method = 'GET',
  Uri? uri,
  String? body,
  List<int>? bodyBytes,
  Map<String, String>? headers,
  String remoteIp = '127.0.0.1',
  int? contentLength,
}) : uri = uri ?? Uri.parse('/'),
     requestedUri = uri ?? Uri.parse('http://localhost/'),
     _bodyBytes = bodyBytes ?? (body != null ? utf8.encode(body) : const []),
     connectionInfo = MockHttpConnectionInfo(remoteIp: remoteIp),
     _contentLengthOverride = contentLength {
  headers?.forEach((key, value) {
    this.headers.set(key, value);
  });
}