LCOV - code coverage report
Current view: top level - Users/duwen/Documents/code/dio/dio/lib/src - response.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 10 10 100.0 %
Date: 2021-11-28 14:37:50 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:convert';
       2             : import 'options.dart';
       3             : import 'headers.dart';
       4             : import 'redirect_record.dart';
       5             : 
       6             : /// Response describes the http Response info.
       7             : class Response<T> {
       8           8 :   Response({
       9             :     this.data,
      10             :     Headers? headers,
      11             :     required this.requestOptions,
      12             :     this.isRedirect,
      13             :     this.statusCode,
      14             :     this.statusMessage,
      15             :     List<RedirectRecord>? redirects,
      16             :     Map<String, dynamic>? extra,
      17             :   }) {
      18          10 :     this.headers = headers ?? Headers();
      19          10 :     this.extra = extra ?? {};
      20          10 :     this.redirects = redirects ?? [];
      21             :   }
      22             : 
      23             :   /// Response body. may have been transformed, please refer to [ResponseType].
      24             :   T? data;
      25             : 
      26             :   /// Response headers.
      27             :   late Headers headers;
      28             : 
      29             :   /// The corresponding request info.
      30             :   late RequestOptions requestOptions;
      31             : 
      32             :   /// Http status code.
      33             :   int? statusCode;
      34             : 
      35             :   /// Returns the reason phrase associated with the status code.
      36             :   /// The reason phrase must be set before the body is written
      37             :   /// to. Setting the reason phrase after writing to the body.
      38             :   String? statusMessage;
      39             : 
      40             :   /// Custom field that you can retrieve it later in `then`.
      41             :   late Map<String, dynamic> extra;
      42             : 
      43             :   /// Returns the series of redirects this connection has been through. The
      44             :   /// list will be empty if no redirects were followed. [redirects] will be
      45             :   /// updated both in the case of an automatic and a manual redirect.
      46             :   ///
      47             :   /// ** Attention **: Whether this field is available depends on whether the
      48             :   /// implementation of the adapter supports it or not.
      49             :   late List<RedirectRecord> redirects;
      50             : 
      51             :   /// Whether this response is a redirect.
      52             :   /// ** Attention **: Whether this field is available depends on whether the
      53             :   /// implementation of the adapter supports it or not.
      54             :   bool? isRedirect;
      55             : 
      56             :   /// Return the final real request uri (maybe redirect).
      57             :   ///
      58             :   /// ** Attention **: Whether this field is available depends on whether the
      59             :   /// implementation of the adapter supports it or not.
      60           2 :   Uri get realUri =>
      61           9 :       (redirects.isNotEmpty) ? redirects.last.location : requestOptions.uri;
      62             : 
      63             :   /// We are more concerned about `data` field.
      64           1 :   @override
      65             :   String toString() {
      66           2 :     if (data is Map) {
      67           2 :       return json.encode(data);
      68             :     }
      69           2 :     return data.toString();
      70             :   }
      71             : }

Generated by: LCOV version 1.14