| Index: pkg/gcloud/lib/http.dart
|
| diff --git a/pkg/gcloud/lib/http.dart b/pkg/gcloud/lib/http.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b6f0c6f50d0dce11d7b5aee705cd4fc76cad3164
|
| --- /dev/null
|
| +++ b/pkg/gcloud/lib/http.dart
|
| @@ -0,0 +1,38 @@
|
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +/// Provides access to an authenticated HTTP client which can be used to access
|
| +/// Google APIs.
|
| +library gcloud.http;
|
| +
|
| +import 'package:http/http.dart' as http;
|
| +
|
| +import 'service_scope.dart' as ss;
|
| +
|
| +const Symbol _authenticatedClientKey = #_gcloud.http;
|
| +
|
| +/// Access the [http.Client] object available in the current service scope.
|
| +///
|
| +/// The returned object will be the one which was previously registered with
|
| +/// [registerAuthClientService] within the current (or a parent) service
|
| +/// scope.
|
| +///
|
| +/// Accessing this getter outside of a service scope will result in an error.
|
| +/// See the `package:gcloud/service_scope.dart` library for more information.
|
| +http.Client get authClientService => ss.lookup(_authenticatedClientKey);
|
| +
|
| +/// Registers the [http.Client] object within the current service scope.
|
| +///
|
| +/// The provided `client` object will be avilable via the top-level
|
| +/// `authenticatedHttp` getter.
|
| +///
|
| +/// Calling this function outside of a service scope will result in an error.
|
| +/// Calling this function more than once inside the same service scope is not
|
| +/// allowed.
|
| +void registerAuthClientService(http.Client client, {bool close: true}) {
|
| + ss.register(_authenticatedClientKey, client);
|
| + if (close) {
|
| + ss.registerScopeExitCallback(() => client.close());
|
| + }
|
| +}
|
|
|