extractBody method

Future<Request> extractBody()

Extracts the request body (form-data / json / urlencoded) into body and prepares the merged view of body+query+params.

Idempotent: only the first call reads the socket. CSRF middleware can materialise the _csrf/_token fields early and the request handler can still call it afterwards without consuming the stream twice.

Implementation

Future<Request> extractBody() async {
  if (_bodyExtracted) return this;
  _bodyExtracted = true;
  _extractCookies();
  final method = request.method.toLowerCase();
  if (method == 'post' ||
      method == 'patch' ||
      method == 'put' ||
      method == 'delete') {
    body = await RequestBody.extractBody(request: request);
  }
  _rebuildAll();
  return this;
}