Line data Source code
1 : import 'dart:convert';
2 : import 'dart:io';
3 :
4 : /// An interface to standardize HTTP responses
5 : abstract class AgattpResponse {
6 : /// The response body, already encoded
7 : String get body;
8 :
9 : /// The response status code
10 : int get statusCode;
11 :
12 : /// The response status reason phrase
13 : String get reasonPhrase;
14 :
15 : /// Whether this response is a redirect or not
16 : bool get isRedirect;
17 :
18 : /// Whether this connection is persistent or not
19 : bool get isPersistentConnection;
20 :
21 : /// The response's headers
22 : HttpHeaders get headers;
23 :
24 : /// The response's cookies, already parsed from the header
25 : List<Cookie> get cookies;
26 : }
27 :
28 : /// Mixing this into a Response allows for easy json decoding and casting to
29 : /// the provided type
30 : mixin JsonResponse<T> on AgattpResponse {
31 : /// Decode the body as a JSON and cast it to T
32 6 : T get json => jsonDecode(body) as T;
33 : }
34 :
35 : /// An extension on the AgattoResponse class mixed with JsonResponse
36 : abstract class AgattpJsonResponse<T> extends AgattpResponse
37 : with JsonResponse<T> {}
|