File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,9 @@ class Client extends http.BaseClient {
66
66
Credentials get credentials => _credentials;
67
67
Credentials _credentials;
68
68
69
+ /// Indicates whether the client is closed or not.
70
+ bool get isClosed => _httpClient == null ;
71
+
69
72
/// Callback to be invoked whenever the credentials refreshed.
70
73
final CredentialsRefreshedCallback ? _onCredentialsRefreshed;
71
74
@@ -110,8 +113,13 @@ class Client extends http.BaseClient {
110
113
await refreshCredentials ();
111
114
}
112
115
116
+ final httpClient = _httpClient;
117
+ if (httpClient == null ) {
118
+ throw http.ClientException ('Client is already closed.' );
119
+ }
120
+
113
121
request.headers['authorization' ] = 'Bearer ${credentials .accessToken }' ;
114
- var response = await _httpClient ! .send (request);
122
+ var response = await httpClient .send (request);
115
123
116
124
if (response.statusCode != 401 ) return response;
117
125
if (! response.headers.containsKey ('www-authenticate' )) return response;
Original file line number Diff line number Diff line change @@ -189,6 +189,26 @@ void main() {
189
189
190
190
expect (client.refreshCredentials (), throwsA (isStateError));
191
191
});
192
+
193
+ test ("won't send a request with closed client" , () {
194
+ var credentials = oauth2.Credentials ('access token' );
195
+
196
+ var client = oauth2.Client (
197
+ credentials,
198
+ identifier: 'identifier' ,
199
+ secret: 'secret' ,
200
+ httpClient: httpClient,
201
+ );
202
+
203
+ expect (client.isClosed, equals (false ));
204
+ client.close ();
205
+ expect (client.isClosed, equals (true ));
206
+
207
+ expect (
208
+ client.read (requestUri),
209
+ throwsA (const TypeMatcher <http.ClientException >()),
210
+ );
211
+ });
192
212
});
193
213
194
214
group ('with invalid credentials' , () {
You can’t perform that action at this time.
0 commit comments