RequestData.fromHttpRequest constructor

RequestData.fromHttpRequest(
  1. BaseRequest request
)

Creates a new request data from an HTTP request.

For now it only supports Request. TODO(codingalecr): Support for MultipartRequest and StreamedRequest.

Implementation

factory RequestData.fromHttpRequest(BaseRequest request) {
  var params = Map<String, dynamic>();
  request.url.queryParametersAll.forEach((key, value) {
    params[key] = value;
  });
  String baseUrl = request.url.origin + request.url.path;

  if (request is Request) {
    return RequestData(
      method: methodFromString(request.method),
      baseUrl: baseUrl,
      headers: request.headers,
      body: request.body,
      encoding: request.encoding,
      params: params,
    );
  }

  throw UnsupportedError(
    "Can't intercept ${request.runtimeType}. Request type not supported yet.",
  );
}