Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(723)

Unified Diff: pkg/http/lib/src/base_client.dart

Issue 810223002: Remove the http package from the repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/http/lib/src/base_client.dart
diff --git a/pkg/http/lib/src/base_client.dart b/pkg/http/lib/src/base_client.dart
deleted file mode 100644
index da38e705000680f1a0ccab648f6dd14392034fed..0000000000000000000000000000000000000000
--- a/pkg/http/lib/src/base_client.dart
+++ /dev/null
@@ -1,169 +0,0 @@
-// Copyright (c) 2012, 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.
-
-library base_client;
-
-import 'dart:async';
-import 'dart:convert';
-import 'dart:typed_data';
-
-import 'base_request.dart';
-import 'client.dart';
-import 'exception.dart';
-import 'request.dart';
-import 'response.dart';
-import 'streamed_response.dart';
-import 'utils.dart';
-
-/// The abstract base class for an HTTP client. This is a mixin-style class;
-/// subclasses only need to implement [send] and maybe [close], and then they
-/// get various convenience methods for free.
-abstract class BaseClient implements Client {
- /// Sends an HTTP HEAD request with the given headers to the given URL, which
- /// can be a [Uri] or a [String].
- ///
- /// For more fine-grained control over the request, use [send] instead.
- Future<Response> head(url, {Map<String, String> headers}) =>
- _sendUnstreamed("HEAD", url, headers);
-
- /// Sends an HTTP GET request with the given headers to the given URL, which
- /// can be a [Uri] or a [String].
- ///
- /// For more fine-grained control over the request, use [send] instead.
- Future<Response> get(url, {Map<String, String> headers}) =>
- _sendUnstreamed("GET", url, headers);
-
- /// Sends an HTTP POST request with the given headers and body to the given
- /// URL, which can be a [Uri] or a [String].
- ///
- /// [body] sets the body of the request. It can be a [String], a [List<int>]
- /// or a [Map<String, String>]. If it's a String, it's encoded using
- /// [encoding] and used as the body of the request. The content-type of the
- /// request will default to "text/plain".
- ///
- /// If [body] is a List, it's used as a list of bytes for the body of the
- /// request.
- ///
- /// If [body] is a Map, it's encoded as form fields using [encoding]. The
- /// content-type of the request will be set to
- /// `"application/x-www-form-urlencoded"`; this cannot be overridden.
- ///
- /// [encoding] defaults to UTF-8.
- ///
- /// For more fine-grained control over the request, use [send] instead.
- Future<Response> post(url, {Map<String, String> headers, body,
- Encoding encoding}) =>
- _sendUnstreamed("POST", url, headers, body, encoding);
-
- /// Sends an HTTP PUT request with the given headers and body to the given
- /// URL, which can be a [Uri] or a [String].
- ///
- /// [body] sets the body of the request. It can be a [String], a [List<int>]
- /// or a [Map<String, String>]. If it's a String, it's encoded using
- /// [encoding] and used as the body of the request. The content-type of the
- /// request will default to "text/plain".
- ///
- /// If [body] is a List, it's used as a list of bytes for the body of the
- /// request.
- ///
- /// If [body] is a Map, it's encoded as form fields using [encoding]. The
- /// content-type of the request will be set to
- /// `"application/x-www-form-urlencoded"`; this cannot be overridden.
- ///
- /// [encoding] defaults to UTF-8.
- ///
- /// For more fine-grained control over the request, use [send] instead.
- Future<Response> put(url, {Map<String, String> headers, body,
- Encoding encoding}) =>
- _sendUnstreamed("PUT", url, headers, body, encoding);
-
- /// Sends an HTTP DELETE request with the given headers to the given URL,
- /// which can be a [Uri] or a [String].
- ///
- /// For more fine-grained control over the request, use [send] instead.
- Future<Response> delete(url, {Map<String, String> headers}) =>
- _sendUnstreamed("DELETE", url, headers);
-
- /// Sends an HTTP GET request with the given headers to the given URL, which
- /// can be a [Uri] or a [String], and returns a Future that completes to the
- /// body of the response as a String.
- ///
- /// The Future will emit a [ClientException] if the response doesn't have a
- /// success status code.
- ///
- /// For more fine-grained control over the request and response, use [send] or
- /// [get] instead.
- Future<String> read(url, {Map<String, String> headers}) {
- return get(url, headers: headers).then((response) {
- _checkResponseSuccess(url, response);
- return response.body;
- });
- }
-
- /// Sends an HTTP GET request with the given headers to the given URL, which
- /// can be a [Uri] or a [String], and returns a Future that completes to the
- /// body of the response as a list of bytes.
- ///
- /// The Future will emit an [ClientException] if the response doesn't have a
- /// success status code.
- ///
- /// For more fine-grained control over the request and response, use [send] or
- /// [get] instead.
- Future<Uint8List> readBytes(url, {Map<String, String> headers}) {
- return get(url, headers: headers).then((response) {
- _checkResponseSuccess(url, response);
- return response.bodyBytes;
- });
- }
-
- /// Sends an HTTP request and asynchronously returns the response.
- ///
- /// Implementers should call [BaseRequest.finalize] to get the body of the
- /// request as a [ByteStream]. They shouldn't make any assumptions about the
- /// state of the stream; it could have data written to it asynchronously at a
- /// later point, or it could already be closed when it's returned. Any
- /// internal HTTP errors should be wrapped as [ClientException]s.
- Future<StreamedResponse> send(BaseRequest request);
-
- /// Sends a non-streaming [Request] and returns a non-streaming [Response].
- Future<Response> _sendUnstreamed(String method, url,
- Map<String, String> headers, [body, Encoding encoding]) {
- return syncFuture(() {
- if (url is String) url = Uri.parse(url);
- var request = new Request(method, url);
-
- if (headers != null) request.headers.addAll(headers);
- if (encoding != null) request.encoding = encoding;
- if (body != null) {
- if (body is String) {
- request.body = body;
- } else if (body is List) {
- request.bodyBytes = body;
- } else if (body is Map) {
- request.bodyFields = body;
- } else {
- throw new ArgumentError('Invalid request body "$body".');
- }
- }
-
- return send(request);
- }).then(Response.fromStream);
- }
-
- /// Throws an error if [response] is not successful.
- void _checkResponseSuccess(url, Response response) {
- if (response.statusCode < 400) return;
- var message = "Request to $url failed with status ${response.statusCode}";
- if (response.reasonPhrase != null) {
- message = "$message: ${response.reasonPhrase}";
- }
- if (url is String) url = Uri.parse(url);
- throw new ClientException("$message.", url);
- }
-
- /// Closes the client and cleans up any resources associated with it. It's
- /// important to close each client when it's done being used; failing to do so
- /// can cause the Dart process to hang.
- void close() {}
-}
« no previous file with comments | « pkg/http/lib/http.dart ('k') | pkg/http/lib/src/base_request.dart » ('j') | pkg/pkg.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698