OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /// Provides access to an authenticated HTTP client which can be used to access |
| 6 /// Google APIs. |
| 7 library gcloud.http; |
| 8 |
| 9 import 'package:http/http.dart' as http; |
| 10 |
| 11 import 'service_scope.dart' as ss; |
| 12 |
| 13 const Symbol _authenticatedClientKey = #_gcloud.http; |
| 14 |
| 15 /// Access the [http.Client] object available in the current service scope. |
| 16 /// |
| 17 /// The returned object will be the one which was previously registered with |
| 18 /// [registerAuthClientService] within the current (or a parent) service |
| 19 /// scope. |
| 20 /// |
| 21 /// Accessing this getter outside of a service scope will result in an error. |
| 22 /// See the `package:gcloud/service_scope.dart` library for more information. |
| 23 http.Client get authClientService => ss.lookup(_authenticatedClientKey); |
| 24 |
| 25 /// Registers the [http.Client] object within the current service scope. |
| 26 /// |
| 27 /// The provided `client` object will be avilable via the top-level |
| 28 /// `authenticatedHttp` getter. |
| 29 /// |
| 30 /// Calling this function outside of a service scope will result in an error. |
| 31 /// Calling this function more than once inside the same service scope is not |
| 32 /// allowed. |
| 33 void registerAuthClientService(http.Client client, {bool close: true}) { |
| 34 ss.register(_authenticatedClientKey, client); |
| 35 if (close) { |
| 36 ss.registerScopeExitCallback(() => client.close()); |
| 37 } |
| 38 } |
OLD | NEW |