of static method

ResponseOrigin of(
  1. Response response
)

Reads the origin stamped on response.

Implementation

static ResponseOrigin of(Response<dynamic> response) {
  final headers = response.headers;
  final replayedAt = headers.value(RecorderInterceptor.replayedHeader);
  if (replayedAt != null) {
    // A stamp we did not write (a non-timestamp value from elsewhere)
    // still marks a replay; it just carries no capture time.
    return ReplayOrigin(recordedAt: DateTime.tryParse(replayedAt));
  }
  final document = headers.value(FixturesInterceptor.documentHeader);
  if (document != null) {
    return FixtureOrigin(
      document: document,
      filePath: headers.value(FixturesInterceptor.filePathHeader),
    );
  }
  return const LiveOrigin();
}