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