@@ -18,124 +18,39 @@ import 'streamed_response.dart';
18
18
/// This is a mixin-style class; subclasses only need to implement [send] and
19
19
/// maybe [close] , and then they get various convenience methods for free.
20
20
abstract class BaseClient implements Client {
21
- /// Sends an HTTP HEAD request with the given headers to the given URL, which
22
- /// can be a [Uri] or a [String] .
23
- ///
24
- /// For more fine-grained control over the request, use [send] instead.
25
21
@override
26
22
Future <Response > head (url, {Map <String , String > headers}) =>
27
23
_sendUnstreamed ('HEAD' , url, headers);
28
24
29
- /// Sends an HTTP GET request with the given headers to the given URL, which
30
- /// can be a [Uri] or a [String] .
31
- ///
32
- /// For more fine-grained control over the request, use [send] instead.
33
25
@override
34
26
Future <Response > get (url, {Map <String , String > headers}) =>
35
27
_sendUnstreamed ('GET' , url, headers);
36
28
37
- /// Sends an HTTP POST request with the given headers and body to the given
38
- /// URL, which can be a [Uri] or a [String] .
39
- ///
40
- /// [body] sets the body of the request. It can be a [String] , a [List<int>]
41
- /// or a [Map<String, String>] . If it's a String, it's encoded using
42
- /// [encoding] and used as the body of the request. The content-type of the
43
- /// request will default to "text/plain".
44
- ///
45
- /// If [body] is a List, it's used as a list of bytes for the body of the
46
- /// request.
47
- ///
48
- /// If [body] is a Map, it's encoded as form fields using [encoding] . The
49
- /// content-type of the request will be set to
50
- /// `"application/x-www-form-urlencoded"` ; this cannot be overridden.
51
- ///
52
- /// [encoding] defaults to UTF-8.
53
- ///
54
- /// For more fine-grained control over the request, use [send] instead.
55
29
@override
56
30
Future <Response > post (url,
57
31
{Map <String , String > headers, body, Encoding encoding}) =>
58
32
_sendUnstreamed ('POST' , url, headers, body, encoding);
59
33
60
- /// Sends an HTTP PUT request with the given headers and body to the given
61
- /// URL, which can be a [Uri] or a [String] .
62
- ///
63
- /// [body] sets the body of the request. It can be a [String] , a [List<int>]
64
- /// or a [Map<String, String>] . If it's a String, it's encoded using
65
- /// [encoding] and used as the body of the request. The content-type of the
66
- /// request will default to "text/plain".
67
- ///
68
- /// If [body] is a List, it's used as a list of bytes for the body of the
69
- /// request.
70
- ///
71
- /// If [body] is a Map, it's encoded as form fields using [encoding] . The
72
- /// content-type of the request will be set to
73
- /// `"application/x-www-form-urlencoded"` ; this cannot be overridden.
74
- ///
75
- /// [encoding] defaults to UTF-8.
76
- ///
77
- /// For more fine-grained control over the request, use [send] instead.
78
34
@override
79
35
Future <Response > put (url,
80
36
{Map <String , String > headers, body, Encoding encoding}) =>
81
37
_sendUnstreamed ('PUT' , url, headers, body, encoding);
82
38
83
- /// Sends an HTTP PATCH request with the given headers and body to the given
84
- /// URL, which can be a [Uri] or a [String] .
85
- ///
86
- /// [body] sets the body of the request. It can be a [String] , a [List<int>]
87
- /// or a [Map<String, String>] . If it's a String, it's encoded using
88
- /// [encoding] and used as the body of the request. The content-type of the
89
- /// request will default to "text/plain".
90
- ///
91
- /// If [body] is a List, it's used as a list of bytes for the body of the
92
- /// request.
93
- ///
94
- /// If [body] is a Map, it's encoded as form fields using [encoding] . The
95
- /// content-type of the request will be set to
96
- /// `"application/x-www-form-urlencoded"` ; this cannot be overridden.
97
- ///
98
- /// [encoding] defaults to UTF-8.
99
- ///
100
- /// For more fine-grained control over the request, use [send] instead.
101
39
@override
102
40
Future <Response > patch (url,
103
41
{Map <String , String > headers, body, Encoding encoding}) =>
104
42
_sendUnstreamed ('PATCH' , url, headers, body, encoding);
105
43
106
- /// Sends an HTTP DELETE request with the given headers to the given URL,
107
- /// which can be a [Uri] or a [String] .
108
- ///
109
- /// For more fine-grained control over the request, use [send] instead.
110
44
@override
111
45
Future <Response > delete (url, {Map <String , String > headers}) =>
112
46
_sendUnstreamed ('DELETE' , url, headers);
113
-
114
- /// Sends an HTTP GET request with the given headers to the given URL, which
115
- /// can be a [Uri] or a [String] , and returns a Future that completes to the
116
- /// body of the response as a String.
117
- ///
118
- /// The Future will emit a [ClientException] if the response doesn't have a
119
- /// success status code.
120
- ///
121
- /// For more fine-grained control over the request and response, use [send] or
122
- /// [get] instead.
123
47
@override
124
48
Future <String > read (url, {Map <String , String > headers}) async {
125
49
final response = await get (url, headers: headers);
126
50
_checkResponseSuccess (url, response);
127
51
return response.body;
128
52
}
129
53
130
- /// Sends an HTTP GET request with the given headers to the given URL, which
131
- /// can be a [Uri] or a [String] , and returns a Future that completes to the
132
- /// body of the response as a list of bytes.
133
- ///
134
- /// The Future will emit an [ClientException] if the response doesn't have a
135
- /// success status code.
136
- ///
137
- /// For more fine-grained control over the request and response, use [send] or
138
- /// [get] instead.
139
54
@override
140
55
Future <Uint8List > readBytes (url, {Map <String , String > headers}) async {
141
56
final response = await get (url, headers: headers);
@@ -186,10 +101,6 @@ abstract class BaseClient implements Client {
186
101
throw ClientException ('$message .' , _fromUriOrString (url));
187
102
}
188
103
189
- /// Closes the client and cleans up any resources associated with it.
190
- ///
191
- /// It's important to close each client when it's done being used; failing to
192
- /// do so can cause the Dart process to hang.
193
104
@override
194
105
void close () {}
195
106
}
0 commit comments